设备系统: MacBook Air M1(AppleSilicon)
Anaconda
anaconda官网 链接🔗
选择mac版本下载,一路默认安装,结束后开启终端验证 conda info 。
virtual packages 与 platform 显示 arm64 安装成功
active environment : base
active env location : /Users/xxx/opt/anaconda3
shell level : 1
user config file : /Users/xxx/.condarc
populated config files :
conda version : 4.13.0
conda-build version : 3.21.9
python version : 3.9.12.final.0
virtual packages : __osx=12.5=0
__unix=0=0
__archspec=1=arm64
base environment : /Users/hailin/opt/anaconda3 (writable)
conda av data dir : /Users/hailin/opt/anaconda3/etc/conda
conda av metadata url : None
channel URLs : https://repo.anaconda.com/pkgs/main/osx-arm64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/r/osx-arm64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /Users/xxx/opt/anaconda3/pkgs
/Users/xxx/.conda/pkgs
envs directories : /Users/xxx/opt/anaconda3/envs
/Users/xxx/.conda/envs
platform : osx-arm64
user-agent : conda/4.13.0 requests/2.27.1 CPython/3.9.12 Darwin/21.6.0 OSX/12.5
UID:GID : 501:20
netrc file : None
offline mode : False
miniforge3
也可以下载 miniforge3,下载地址为:链接🔗
在Download中选择 Apple Silicon 版本:arm64 (Apple Silicon)将下载好的脚本移动到用户目录,并赋予执行权限,安装即可。
安装
下载完以后在terminal依次输入以下三个命令,后面的命令也都是在terminal输入
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
查看版本
conda --version
python --version
创建环境,指定为python3.9
env_name是环境名字
conda create -n env_name python==3.9
激活环境
conda activate env_name
安装jupyter
conda install jupyter notebook
使用jupyter
jupyter notebook
Tensorflow
打开终端,在conda环境中,默认安装2.8版本的tensorflow,也可以指定版本。最好默认
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
查看tensorflow
import tensorflow as tf
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# 查看tensorflow版本
print('tensorflow Version :'+tf.__version__)
PyTorch
PyTorch官网 链接🔗
conda create -n torchEnv python=3.8
conda activate torchEnv
conda install pytorch torchvision torchaudio -c pytorch
终端The following NEW packages will be INSTALLED:出现了 pytorch pytorch/osx-arm64::pytorch-1.12.1-py3.8_0
终端输入python进入编程环境
Python 3.8.13 (default, Mar 28 2022, 06:13:39)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5, 3)
>>> print(x)
tensor([[0.1943, 0.7646, 0.3717],
[0.1829, 0.6984, 0.9232],
[0.6371, 0.0138, 0.2590],
[0.4855, 0.7717, 0.4801],
[0.6527, 0.8453, 0.6713]])
>>> torch.__version__
PyCharm
将虚拟环境设置到IDE便于管理切换操作路径为Preferences -> Project -> Python Interpreter 点击设计图标 选择 Add -> Conda Environment 涂鸦部分为电脑用户名。
