安装 Tensorflow2
Contents
安装 Anaconda
https://www.anaconda.com/products/individual
根据系统选择下载不同的 anaconda 安装:
这里安装的是 MacOS 的软件包,安装完成后使用 conda 命令查看是否安装成功:
$ conda --version
conda 4.9.2
更换 conda 镜像源
查看用户目录下的 .condarc
文件:
更换成清华大学镜像源
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
运行 conda clean -i
清除索引缓存,保证用的是镜像站提供的索引。
运行 conda create -n myenv numpy
测试一下吧。
更换 pip 的镜像源
默认的 pip 下载地址速度较慢,我们将其更换成清华大学的镜像地址:
$ pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /Users/yaoxiaojiao/.config/pip/pip.conf
详情查看:pypi 镜像使用帮助
安装 Tensorflow 2.2
创建一个 TF2.2 的 conda 实验环境并安装相关软件包:
conda create -n TF2.2 python=3.8
进入 TF2.2 环境中:
conda activate TF2.2
安装英伟达显卡的 SDK
Tensorflow2.1 匹配的 cuda toolkit 是 10.1,由于我的电脑上没有英伟达的显卡,无法安装,先记录下安装命令,后续找台有英伟达显卡的机器实验:
conda install cudatoolkit=10.1
tf2.1对应的英伟达显卡的深度学习软件包版本为 cudnn7.6
conda install cudnn=7.6
mac pro 由于没有英伟达的显卡,我们可以尝试通过 pycharm 远程连接解释器的方式,在远程一台有显卡的服务器上进行解析。详情参考:Remote Debugging with PyCharm
安装 tensorflow 2.2
pip install tensorflow==2.2.0
验证 tensorflow2.0 安装成功:
import tensorflow as tf
tf.__version__
参考
https://zhuanlan.zhihu.com/p/87123943
https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config