MacOS创建TensorFlow虚拟环境(conda)

# 打开terminal,创建并激活名为tensorflow的虚拟环境
conda create -n tensorflow
source activate tensorflow
(tensorflow) ➜  ~ conda install -c apple tensorflow-deps

source命令:

sourceFileName:在当前bash环境下读取并执行FileName中的命令

注:该命令通常用命令“.”来替代。如:source.bash_rc与..bash_rc是等效

# 为conda添加清华源channels
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 --set show_channel_urls yes
# 安装TensorFlow包
pip install tensorflow-macos
pip install tensorflow-metal

注意:遇到下不了的包(runtimeout),google找对应的轮子下载

# 检查TensorFlow环境是否安装成功
import tensorflow as tf
# Check for TensorFlow GPU access
print(f"TensorFlow has access to the following devices:\n{tf.config.list_physical_devices()}")
# See TensorFlow version
print(f"TensorFlow version: {tf.__version__}")

你可能感兴趣的:(Python,Env,tensorflow,macos,conda)