修改默认镜像为清华的镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
清华大学开源软件镜像站
创建虚拟环境
如果Anaconda支持高于python3.6的版本,则可创建低于python3.6的虚拟环境,
例如,Anaconda3-2020.07-Linux-x86_64.sh
支持最高python版本为3.8,则可创建名为tensorflow
的python3.6的虚拟环境:conda create -n tensorflow python=3.6
删除虚拟环境
conda remove -n tensorflow --all
列举出所有环境:
conda info -e
安装tensorflow
查看tensorflow-gpu
有哪些版本:conda search tensorflow-gpu
查看tensorflow
有哪些版本:conda search tensorflow
conda create -n tensorflow2.1.0 python=3.7
GPU版本 pip3 install tensorflow_gpu==2.1.0
CPU版本 pip install tensorflow==1.4.0
手动指定源:
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow_gpu==2.1.0
查看tensorflow_gpu是否启用了GPU:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
输出如下信息,则说明启用了GPU:
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 12314334038188697173
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 10304169984
locality {
bus_id: 1
links {
}
}
incarnation: 13833105769355917182
physical_device_desc: "device: 0, name: NVIDIA GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1"
]
CUDA版本
linux
nvcc --version
, nvcc -V
cat /usr/local/cuda/version.txt
windows
nvcc --version
CUDNN版本
linux
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
windows
进入 CUDA 的安装目录查看文件 cudnn.h
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include\cudnn.h
CUDA库找不到
虽然安装了CUDA但是运行时发现找不到类似如下库,原因可能是:

- 版本不对,例如使用GPU的TensorFlow不同版本对CUDA和cuDNN的版本要求不一样。具体可查看:https://tensorflow.google.cn/install/source
- 安装了CUDA版本也对,但是路径没加
vi ~/.bash_profile
,然后将cuda安装路径写进去(参考Linux常见问题及解决方案),然后再执行source ~/.bash_profile
即可:

还有人用tensorflow0.8吗,请告诉我为什么
conda create -n tensorflow0.8 python=3.5
下载 https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl
,可能无法直接安装,因为创建的虚拟环境python是3.5的,安装文件是python3.4的(报错tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl is not a supported wheel on this platform.
),重命名后方可安装(参考Cannot install tensorflow on fresh ubuntu partition: tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl is not a supported wheel on this platform):
wget https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl
mv tensorflow-0.8.0-cp34-cp34m-linux_x86_64.whl tensorflow-0.8.0-cp35-cp35m-linux_x86_64.whl
pip install tensorflow-0.8.0-cp35-cp35m-linux_x86_64.whl
安装opencv
当需要使用opencv但未安装时会提示:ImportError: No module named 'cv2'
安装方法:
conda install -c https://conda.anaconda.org/menpo opencv
或:
pip install --upgrade opencv-python
virtualenv创建虚拟环境
sudo apt-get install python3-pip python3-dev python3-virtualenv
-
参数
--system-site-packages
表示已经安装到系统Python环境中的所有第三方包会复制过来
virtualenv --system-site-packages ~/env/tensorflow
-
参数
--no-site-packages
表示安装到系统Python环境中的所有第三方包都不会复制过来,这样就得到了一个不带任何第三方包的“干净”的Python运行环境。
virtualenv --no-site-packages ~/env/tensorflow
激活虚拟环境:
source ~/env/tensorflow/bin/activate
CUDA版本不对
tensorflow训练的时候报错:failed to run cuBLAS routine cublasSgemm_v2: CUBLAS_STATUS_EXECUTION_FAILED
报错原因是tensorflow版本与CUDA版本不匹配。
参考:https://blog.csdn.net/thunder_k/article/details/90610218

卸载anaconda
https://docs.anaconda.com/anaconda/install/uninstall/?highlight=uninstall