Mac M1 Big Sur Python setup for Data Analysis
Data Analysis on a remote basis has its own restrictions in terms of picking the right device for work. I usually use Windows but recently I had to switch to macOS M1-based laptop and here’s my story…
In this story, I’ll try to provide the most comprehensive guide about how to set up a new M1 mac for using main data-related libraries. I tried multiple methods and found that using Conda-miniforge is the optimal way.
Tools, that will be used
- VS Code
- Conda miniforge (because full anaconda has some law restrictions)
- Python
- Jupiter notebooks
Solution 1. Conda-based installation
- The first step to install packages using Conda is to pick the latest installer from its GitHub repo here. In our case, we need the version for Mac with Apple Silicon (M1) platform and the link is:
https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
As a result, we will download a.sh
file which we will use later in the second step. - Open Terminal and navigate to the folder where you downloaded the file from the first step. You can do that using
cd
- After navigating un Termial to the folder containing the downloaded file copy the following command:
bash Miniforge3-MacOSX-arm64.sh
The final line of output should look like this:Thank you for installing Miniforge3!
Now you need to close and open the Terminal again. - I faced an issue here — MacOS BigSur does not recognize
conda
command. If you do not have this problem — skip step 4.
4.1. To solve this issue type: nano ~/.zshrc
in your terminal to edit .zshrc
file. You will see the following screen:
4.2 Replace YOUR USER NAME
with a username of your computer and add line export PATH=”/Users/YOUR USER NAME/miniforge3/bin:$PATH”
to the bottom of this file. Then press command
+X
and then y
to save the file. Then close Terminal and open it again.
5. Now, when Conda is set up and running all we need to do is to runconda install numpy scipy matplotlib pandas scikit-learn
the command.
numpy, scipy, matplotlib, pandas, and scikit-learn are Python libraries, so you can pick the one you need. The command might look like this:conda install pandas
6. To start using Jupiter notebooks install Visual Studio Code (VS Code), open it, and create any file with .ipynb
format. VS Code will automatically offer you to install Jupiter
extension.
6.1 In case after running the test query you see an error that there is no such module, but you installed it. Like this one:
The problem is that VS Code using your default Python instead of Conda one. To fix that you have to change Pythong interpreter by clicking on the top right corner as it is shown on the screenshot:
Then pick Python interpretator with (conda) in it’s name. If you installed all packages using Conda — It should fix the “No module” errors.
Now everything should work normally.
Thanks for reading this article.
I hope this information will be useful for you and good luck with data!
Alex