安装Anaconda
从别人的文件夹那里cp个Anaconda3-5.0.1-Linux-x86_64.sh到我的目录下,然后安装
bash Anaconda3-5.0.1-Linux-x86_64.sh
一路按Enter和yes,最后问是否安装VS的时候按no,就安装完毕了。
安装过程中它会把Anaconda的路径加入到 ~/.bashrc 中,安装完之后要激活安装
source ~/.bashrc
验证是否安装成功:
anaconda
安装成功之后默认有一个python3.6,可以python查看。
如果没有成功,可能是需要自己把Anaconda路径加入环境变量中。建议重新安装。
卸载Anaconda
rm -rf anaconda3
下面推荐xshell同时开两个会话并行安装pytorch和tensorflow
Pytorch
示例安装torch0.4.0版本,建议用conda
方法1:conda
先加入清华源,后用conda安装
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda install pytorch=0.4.0 torchvision
方法2:pip
我原本的方法(太慢):
pip install http://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-linux_x86_64.whl
pip install torchvision
师兄的方法(安装失败):
pip install torch==1.1.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
所以还是建议用conda
打开python检查是否安装成功:
import torch
print(torch.cuda.is_available()) #输出True说明成功
print(torch.__version__)
Tensorflow
用conda命令安装,会自动检测安装合适的tensorflow版本
conda install tensorflow-gpu
检查是否安装成功
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow! I am IT Xiao Ding Dang!')
sess = tf.Session()
sess.run(hello)
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
此外可以参考之前写的博客: