目录
一、python3安装
- ssh之后到根目录(例如/home/shgx/software)[shgx为用户名],下载指定版本的Python3源码:
wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
- 解压文件:
tar -xvf Python-3.5.6.tgz
- 在根目录下(/home/shgx)创建如下路径(mkdir -p bin/Python3),使用pwd检查Python3下的路径为/home/shgx/bin/Python3
- 打开刚刚解压的文件目录cd /home/shgx/software/Python-3.5.6/(下面的步骤5.6.7都在此目录下执行)
- 进行检测
./configure --prefix=/home/shgx/bin/Python3
- 开启优化功能
./configure --enable-optimizations
- 执行指令进行编译
make
- 进行安装
make install
- 打开cd /home/shgx/bin/Python3/bin查看是否运行成功
执行python3以及pip3或者/pip3
- 成功之后在根目录下(/home/shgx)创建软链接
ln -s /home/shgx/bin/Python3/bin/python3 python3
- 以上即完成Python安装,可以在根目录下执行python3
./python3
二、anaconda安装
1.官网列有所有anaconda安装包:
https://repo.continuum.io/archive/index.html
2 Linux下使用wget指令获取相关安装包,指令wget + 下载链接
;
3.sh指令安装时,安装指令bash + anaconda安装包(安装包应该是.sh文件)
,如果是在自己的用户目录下安装需要制定安装目录,不然默认安装时在/bin之下,这是系统目录,需要super权限;
4.安装成功之后,可以通过指令conda init
对环境进行激活,此时在文件~/.bashrc
中一般般会出现anaconda的安装路径等相关信息;
如果在安装完成时,并没有执行上述conda init
,则需要在 ~/.bashrc 文件中自动添加相关路径,然后使用命令source ~/.bashrc
激活即可;
添加的路径信息,需要如下操作:
首先打开文件vim ~/.bashrc
#打开之后在文件末尾添加如下语句即可
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/zhangxu/software/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/zhangxu/software/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/zhangxu/software/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/zhangxu/software/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
source ~/.bashrc
#激活环境
三、 anaconda 添加国内源
1 添加conda国内镜像:
- 清华源
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 Forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
# msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
# bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
#menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
# pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
- 中科大源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
2 删除国内源
换回conda的默认源。查看了conda config的文档后,发现直接删除channels即可。
conda config --remove-key channels
3 conda本地包安装
conda install --use-local [pak]
4 对于pip修改国内镜像源和本地安装,具体见下:
https://blog.csdn.net/yangwangnndd/article/details/90579809
四、使用anaconda安装tensorflow-gpu版本
- 安装tensorflow时,需要tensorflow版本和cuda CUDNN版本保持一致,详细信息查看
查看CUDA版本号: nvcc -V
查看CUDNN版本号:cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
版本对应网址:https://www.tensorflow.org/install/install_sources#tested_source_configurations
- 下面进行安装
python --version chan查看Python版本号
conda create -n yangwang pip python=3.6 #yangwang 为 虚拟环境名称
conda activate yangwang #激活虚拟环境
conda install tensorflow-gpu==1.5.0 #安装的tensorflow版本需要和cuda cudnn相对应
conda虚拟环境下卸载安装时:
1.查看安装的包: conda list
2.检查更新当前conda:conda update conda。
3.环境中安装某个安装包:conda install -n your_env_name [package],其中[]中package为需安装的包名,your_env_name为环境名称。
4.环境中删除某个包:conda remove --name yangwang tensorflow-estimator #yangwang为虚拟环境名称 tensorflow-estimator为安装的具体包的名称
5.删除整个环境:conda remove -n your_env --all
- 测试
conda activate yangwang / conda activate yangwang#首先激活tensorflow环境
python #启动python环境
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print (sess.run(hello))
conda deactivte # 退出Python后退出虚拟环境:
注意:目前(2019.05.29)
- 不支持最新cuda版本10.1,一般使用10.0或者9.0;
- Python3.7支持不够完善,还有许多坑,一般使用3.6或者3.5版本;
五、 anaconda 创建虚拟环境安装pytorch[常用]
- 创建虚拟环境,需要查看Python版本 :
conda create -n pytorch python=3.6
- 参看 Python版本和anaconda版本以及CUDA版本,命令见上 ;
- 官网上根据对应机器配置安装相应的pytorch版本:
https://pytorch.org/
- 安装pytorch:
conda install pytorch torchvision cudatoolkit=9.0 cudnn
注意:
- torch存在安装时cuda版本和运行时版本不一致问题,二者一定要保持一致,同样不支持最新的cuda版本10.1(2019.05.29),对于cuda9.2版本支持不完善;
- torch-0.4.1默认安装cuda版本为9.0,但是对于本机cuda-10.0版本的需要单独安装为cuda-10.0
- 安装torch时,不要添加官网指令的后缀的
-c pytorch
, 否则编译很慢
六、CUDA安装
- CUDA官网(所有版本安装包列表),wget 指令获取:
https://developer.nvidia.com/cuda-toolkit-archive
- 安装CUDA
- 添加环境变量,即安装目录
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.1/lib64
export PATH=$PATH:/usr/local/cuda-10.1/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-10.1
- source ~/.bashrc
- 基本使用指令:
- 显示显卡使用情况:nvidia-smi
- 显示版本号:nvcc -V
- 成功