I recently purchased my first Mac. It is a MacBook Pro 13" M1, great little machine with lots of power. The work I do is Python, ansible, and other miscellaneous development projects connecting to databases, lately PostgreSQL. I do use a laptop for photography work as well. The first steps were getting the development environment up and running. Microsoft VS Code went in smoothly and synced everything once connected to my Microsoft account.
Next was installing Python. This was interesting as I wanted at least Python 3.8+ and for the M1 it seemed that 3.9.1 was the first real supported release. The M1 with Big Sur comes with Python 2.7 and you do not want to replace it.
I found two ways to install Python 3.9, one using pyenv and one using brew. I did find that you do not want to mix the two. I removed both and tired just pyenv by itself and got lots of errors with matplotlib, pandas, and psycopg2. Most of the solutions I found did not seem to help and maybe I did not do the right things. So I removed the pyenv install and went the brew install of Python 3.9.1 and here are the steps I used to get them the modules I wanted installed and working.
First installing Python 3.9.1
First thing I noticed with this installation is that everything ends up in /opt/homebrew and you will need to add directories to your path.
In my case homebrew was installed in /opt/homebrew by default. I followed the instructions on the Brew Homepage. Update your .zshrc to update the PATH on terminal startup.
export PATH="/opt/homebrew/bin:$PATH"
$ brew install openssl
$ brew install python@3.9
$ brew install openblas$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install cython --no-use-pep517$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install numpy --no-use-pep517$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install pandas --no-use-pep517$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install pybind11 --no-use-pep517$ OPENBLAS="$(brew --prefix openblas)" MACOSX_DEPLOYMENT_TARGET=11.1 python3 -m pip install scipy --no-use-pep517$ brew install libjpeg zlib$ python3 -m pip install pillow$ python3 -m pip install matplotlib
$ brew install postgresql@12
$ which pip3
export LDFLAGS="-L/opt/homebrew/opt/openssl/lib"export CPPFLAGS="-L/opt/homebrew/opt/openssl/include"
$ pip3 install psycopg2-binary
#!/usr/bin/env python3