python & tensorFlow安装(非root权限)

一、python3安装


  1. ssh之后到根目录(例如/home/shgx/software)[shgx为用户名],下载指定版本的Python3源码:

wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz

  1. 解压文件:

tar -xvf Python-3.5.6.tgz

  1. 在根目录下(/home/shgx)创建如下路径(mkdir -p bin/Python3),使用pwd检查Python3下的路径为/home/shgx/bin/Python3
  2. 打开刚刚解压的文件目录cd /home/shgx/software/Python-3.5.6/(下面的步骤5.6.7都在此目录下执行)
  3. 进行检测

./configure --prefix=/home/shgx/bin/Python3

  1. 开启优化功能

./configure --enable-optimizations

  1. 执行指令进行编译

make

  1. 进行安装

make install

  1. 打开cd /home/shgx/bin/Python3/bin查看是否运行成功

执行python3以及pip3或者/pip3

  1. 成功之后在根目录下(/home/shgx)创建软链接

ln -s /home/shgx/bin/Python3/bin/python3 python3

  1. 以上即完成Python安装,可以在根目录下执行python3

./python3

二、 安装tensorFlow

  1. 下载tensorFlow源码

git clone https://github.com/tensorflow/tensorflow

通过以下指令 git clone https://github.com/tensorflow/tensorflow下载tensorflow源码时,遇到报错:error: RPC failed; curl 56 GnuTLS recv error (-54): Error in the pull function

原因如下:

  1. Linux git默认缓存存过小,通过以下指令修改:

git config --global http.postBuffer 524288000

  1. clone速度较慢
    1)修改压缩配置:
    git config --global core.compression -1
    2)修改配置文件
    export GIT_TRACE_PACKET=1
    export GIT_TRACE=1
    export GIT_CURL_VERBOSE=1

(三)使用anaconda安装tensorflow-gpu版本

  1. 安装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

  1. 下面进行安装

python --version chan查看Python版本号
conda create -n yangwang pip python=3.7 #yangwang 为 虚拟环境名称
source 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为安装的具体包的名称

  1. 测试

source activate yangwang / conda activate yangwang#首先激活tensorflow环境
python3 #启动python环境
import tensorflow as tf
hello = tf.constant(‘Hello, TensorFlow!’)
sess = tf.Session()
print (sess.run(hello))
退出Python后退出虚拟环境:
source deactivate yangwang / conda deactivte

(四)anaconda 创建虚拟环境安装pytorch

  1. 创建虚拟环境,需要查看Python版本 :

conda create -n pytorch python=3.7

  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 config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

  1. 参看 Python版本和anaconda版本以及CUDA版本,命令见上 ;
    4.官网上根据对应机器配置安装相应的pytorch版本:

https://pytorch.org/

  1. 安装pytorch:

conda install pytorch torchvision cudatoolkit=9.0 -c pytorch

猜你喜欢

转载自blog.csdn.net/yangwangnndd/article/details/89068297
今日推荐