无Root权限的Python+TensorFlow环境安装

一、248机器Python3源码安装

  1. ssh之后到根目录(例如/home/shgx)[shgx为用户名],下载指定版本的Python3源码:wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
  2. 解压文件tar -xvf Python-3.5.6.tgz
  3. 在根目录下(/home/shgx)创建如下路径(mkdir -p bin/Python3),使用pwd检查Python3下的路径为/home/shgx/bin/Python3
  4. 打开刚刚解压的文件目录cd /home/shgx/Python-3.5.6/(下面的步骤5.6.7都在此目录下执行)
  5. 执行./configure --prefix=/home/shgx/bin/Python3进行检测
  6. 执行make进行编译
  7. 执行make install 进行安装
  8. 打开cd /home/shgx/bin/Python3/bin执行python3以及pip3或者/pip3查看是否运行成功,
  9. 成功之后在根目录下(/home/shgx)创建软链接
    ln -s /home/shgx/bin/Python3/bin/python3 python3
  10. 这样在你的根目录下就可以执行python3

二、248机器安装GPU-TenSorFlow

  1. 可以通过上面创建软连接的方式同样创建pip3的软连接,或者进入直接调用目录/home/shgx/bin/Python3/bin/pip3进行安装
  2. 安装GPU版本的TensorFlow
    /home/shgx/bin/Python3/bin/pip3 install tensorflow-gpu==1.2
  3. 安装Keras/home/shgx/bin/Python3/bin/pip3 install keras==2.1.5
  4. 以此类推...可以安装其他库

三、 211机器源码安装TensorFlow

  1. 确认安装了Python3(我的安装路径为/home/shgx/Python3.5)以及numpy、wheel
  2. 查看CUDA版本,并记录版本为7.1.2
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 1
#define CUDNN_PATCHLEVEL 2
--
#define CUDNN_VERSION    (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"

3.在本地目录下创建临时文件夹如:mkdir -p tmp/tensorflow_pkg

  1. 下载tensorflow源码git clone https://github.com/tensorflow/tensorflow
  2. 以上是准备工作,下面开始安装,首先进入tensorflow文件夹cd tensorflow,切换分支git checkout r1.6
  3. 执行./configure进行检测,configure成功后,依然还在tensorflow的根目录下输入以下命令(Yes or No可根据你的需要进行选择,其中需要填写CUDA版本)
[shgx@deep-worker1 tensorflow]$ ./configure
You have bazel 0.11.1- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: /home/shgx/Python3.5/bin/python3


Found possible Python library paths:
  /home/shgx/Python3.5/lib/python3.5/site-packages
Please input the desired Python library path to use.  Default is [/home/shgx/Python3.5/lib/python3.5/site-packages]

Do you wish to build TensorFlow with jemalloc as malloc support? [Y/n]: 
jemalloc as malloc support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Google Cloud Platform support? [Y/n]: n
No Google Cloud Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Hadoop File System support? [Y/n]: n
No Hadoop File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Amazon S3 File System support? [Y/n]: n
No Amazon S3 File System support will be enabled for TensorFlow.

Do you wish to build TensorFlow with Apache Kafka Platform support? [y/N]: 
No Apache Kafka Platform support will be enabled for TensorFlow.

Do you wish to build TensorFlow with XLA JIT support? [y/N]: 
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with GDR support? [y/N]: 
No GDR support will be enabled for TensorFlow.

Do you wish to build TensorFlow with VERBS support? [y/N]: 
No VERBS support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: 
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: y
CUDA support will be enabled for TensorFlow.

Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to default to CUDA 9.0]: 9.1


Please specify the location where CUDA 9.1 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: 


Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 


Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:7.1.2


Please specify the cuDNN version you want to use. [Leave empty to default to cuDNN 7.0]: 


Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:


Do you wish to build TensorFlow with TensorRT support? [y/N]: 
No TensorRT support will be enabled for TensorFlow.

Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size. [Default is: 6.1,6.1,6.1,6.1]


Do you want to use clang as CUDA compiler? [y/N]: 
nvcc will be used as CUDA compiler.

Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]: 


Do you wish to build TensorFlow with MPI support? [y/N]: 
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: 
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See tools/bazel.rc for more details.
    --config=mkl            # Build with MKL support.
    --config=monolithic     # Config for mostly static monolithic build.
    --config=tensorrt       # Build with TensorRT support.
Configuration finished
  1. configure成功后,依然还在tensorflow的根目录下输入以下命令(大约20分钟)
bazel build --config=opt --config=cuda tensorflow/tools/pip_package:build_pip_package
  1. 之后执行:
bazel-bin/tensorflow/tools/pip_package/build_pip_package /home/shgx/tmp/tensorflow_pkg
  1. 最后cd /tmp/tensorflow_pkg切换到/tmp/tensorflow_pkg目录下,使用pip3进行安装pip3 install tensorflow-1.6.0-cp35-cp35m-linux_x86_64.whl(具体名字和你的python版本有关)

四、GPU使用

  1. 使用nvidia-smi查看GPU使用情况
  2. 选择一块GPU进行实验CUDA_VISIBLE_DEVICES=0 python3 xxx.py
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,658评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,482评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,213评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,395评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,487评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,523评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,525评论 3 414
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,300评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,753评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,048评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,223评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,905评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,541评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,168评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,417评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,094评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,088评论 2 352

推荐阅读更多精彩内容