M1 chip configuration python environment

Install Anaconda

Anaconda released a version supporting the M1 chip on June 7 this year (22):

anaconda download description
Before this, you can use anaconda by installing miniforge;
download address: https://github.com/conda-forge/miniforge/releases
Select the MacOSX-arm64 version of Miniforge3 to download.
After downloading, open the terminal under the Downloads path and enter sh Miniforge3 -4.11.0-0-MacOSX-arm64.sh, just enter yes when prompted to enter yes/no.
Verify whether the installation is complete: enter:
conda --version in the terminal
. If conda and version number appear, it means it has been installed. Success, the latest version is python version 3.9.12;

It is more convenient to download the full version directly from the anaconda official website:
the address to download the latest version: https://www.anaconda.com/products/distribution
and the address to view the historical version: https://repo.anaconda.com/archive/

conda replaces domestic source

View source

conda config --show-sources

Add warehouse

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

You can add them all, or you can select the main ones to add;

ps: If you see errors reported in other people's blogs, you can handle it this way:
check and change the configuration
conda config --show.
If - defaults exists, you need to delete this line.
conda config --remove channels defaults

Install jupyter

The miniforge version does not have jupyter:
enter in the terminal

sudo pip install jupyter

Like jupyter-lab:

sudo pip install jupyterlab

Install pycharm

Link: https://www.jetbrains.com/pycharm/download/#section=mac
drop-down selection.dmg (Apple silicon)
pycharm download interface

Configure environment variables

Open the file in the terminal: vi ~/.zshrc,
enter i to enter editing mode, then enter: export PATH=/your own path/anaconda3/bin:$PATH
esc to exit editing, :wq to save and exit.
Make the modified files take effect immediately. Terminal input: source ~/.zshrc undo

Install pytorch (gpu version):

Download address:
https://github.com/wizyoung/AppleSiliconSelfBuilds/blob/main/builds/torch-1.8.0a0-cp39-cp39-macosx_11_0_arm64.whl
You can also go directly to the official website:
https://pytorch.org/get- started/locally/#macos-version

Pay attention to the version format, pytorch already supports the M1 gpu version;

pip install torchvision
conda install future pyyaml tqdm fsspec tensorboard
pip install pytorch-lightning
pip install librosa

Install Tensorflow

tensorflow has supported m1 gpu for a long time:
installation:

conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

If it has been installed before, the official website recommends uninstalling and reinstalling:

python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
conda install -c apple tensorflow-deps --force-reinstall

Or virtual environment:

conda install -c apple tensorflow-deps --force-reinstall -n my_env

Excerpted from Apple’s official website: https://developer.apple.com/metal/tensorflow-plugin/

Install brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Problems you may encounter:
1. Network problems:
-curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
Solution:
Switch domestic source:

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" 

Reference:
[1]: https://blog.csdn.net/weixin_41466947/article/details/107377071
[2]: https://www.jianshu.com/p/bbeff3ea9c70

Guess you like

Origin blog.csdn.net/weixin_39747882/article/details/126649413