Python and Pandas on a Mac M1

Recently I was going through the book Getting Structured Data from the Internet - this had been going pretty smoothly until I attempted to install Pandas on a Mac M1

 219 warnings and 17 errors generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------

  ERROR: Failed building wheel for pandas
Failed to build pandas
ERROR: Could not build wheels for pandas which use PEP 517 and cannot be installed directly

To this point I had just been using the standard pyenv, virtualenv and a Jupyter Notebook. From a strictly development perspective I would advise steering clear of the M1 for the time being (Sep. 2021) as there are constantly issues such as this. It leads down obscure rabbit holes and general time wasters that while they may be helpful for learning - just aren't that useful for overall productivity. I ran into similar issues with Node.JS that I've had with Python. These M1 machines have been out a while now and the progress on community supported packages is just not there. This blog post, Top 3 Reasons Why I Sold My M1 Macbook Pro as a Data Scientist pretty much sums up my sentiments.

So a quick google returned a few data science blogs the more useful being here.

Beginning at Step 3 of the afformentioned blog I need MiniForge. MiniForge is a minimal install of Conda. I'm not in data science by trade but am familiar enough with Conda as an environment manager for data wrangling type work and I enjoy the Jupyter Notebook experience of working through problems and general code sketchbooking.

Using homebrew for the install

brew install miniforge
conda
...

usage: conda [-h] [-V] command ...

Create an environment.yml for Conda

touch environment.yml && vim environment.yml
name: getting_structured_data
channels:
- conda-forge
dependencies:
- requests
- numpy
- pandas

Then:

conda env create --file=environment.yml --name=Getting_Structured_Data
conda activate Getting_Structured_Data

First run was an error:

CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.

I am a zsh user so:

conda init zsh
...
==> For changes to take effect, close and re-open your current shell. <==

Close and re-open the shell:

which pip
      /opt/homebrew/Caskroom/miniforge/base/envs/Getting_Structured_Data/bin/pip
pip install pandas numpy requests

And we're off to the races.

In this book tutorial - the author is using sentiment analysis from Algorithmia for which you have to setup an API Key - so I add python-dotenv so as not to commit my personal key to source control

conda install python-dotenv

Sean Mayhew with my Kids

Sean Mayhew

Code. Dirt. Renaissance.