tensorflow 虚拟环境配置

转载自:

http://wiki.jikexueyuan.com/project/tensorflow-zh/get_started/os_setup.html

http://www.cnblogs.com/simplelovecs/p/5149982.html


tensorflow的Virtualenv安装方式安装

 本文介绍了如何在ubuntu上以virtualenv方式安装tensorflow。  

安装pip和virtualenv:

1
2
3
4
5
6
# Ubuntu/Linux 64-bit
sudo  apt-get  install  python-pip python-dev python-virtualenv
 
# Mac OS X
sudo  easy_install pip
sudo  pip  install  --upgrade virtualenv

 创建 Virtualenv 虚拟环境:

  进入你想安装tensorflow的父目录下,然后执行下面命令建立虚拟环境:

1
virtualenv --system-site-packages tensorflow

 激活虚拟环境并安装tensorflow:

  对于python27,则执行如下命令:

1
2
3
4
5
6
7
8
9
10
11
12
source  . /tensorflow/bin/activate   # If using bash
source  . /tensorflow/bin/activate .csh   # If using csh
(tensorflow)$   # Your prompt should change
 
# Ubuntu/Linux 64-bit, CPU only:
pip  install  --upgrade https: //storage .googleapis.com /tensorflow/linux/cpu/tensorflow-0 .6.0-cp27-none-linux_x86_64.whl
 
# Ubuntu/Linux 64-bit, GPU enabled:
pip  install  --upgrade https: //storage .googleapis.com /tensorflow/linux/gpu/tensorflow-0 .6.0-cp27-none-linux_x86_64.whl
 
# Mac OS X, CPU only:
pip  install  --upgrade https: //storage .googleapis.com /tensorflow/mac/tensorflow-0 .6.0-py2-none-any.whl

   对于python3则执行如下命令:

1
2
3
4
5
6
7
8
9
10
11
12
source  . /tensorflow/bin/activate   # If using bash
source  . /tensorflow/bin/activate .csh   # If using csh
(tensorflow)$   # Your prompt should change
 
# Ubuntu/Linux 64-bit, CPU only:
pip  install  --upgrade https: //storage .googleapis.com /tensorflow/linux/cpu/tensorflow-0 .6.0-cp34-none-linux_x86_64.whl
 
# Ubuntu/Linux 64-bit, GPU enabled:
pip  install  --upgrade https: //storage .googleapis.com /tensorflow/linux/gpu/tensorflow-0 .6.0-cp34-none-linux_x86_64.whl
 
# Mac OS X, CPU only:
pip3  install  --upgrade https: //storage .googleapis.com /tensorflow/mac/tensorflow-0 .6.0-py3-none-any.whl

 测试安装:

  在终端执行如下命令进入python shell环境:

1
python

   在python shell环境中测试:

1
2
3
4
5
6
7
8
9
10
>>>  import  tensorflow as tf
>>> hello  =  tf.constant( 'Hello, TensorFlow!' )
>>> sess  =  tf.Session()
>>>  print (sess.run(hello))
Hello, TensorFlow!
>>> a  =  tf.constant( 10 )
>>> b  =  tf.constant( 32 )
>>>  print (sess.run(a  +  b))
42
>>>
  •  如果遇到如下错误:
1
2
     _mod = imp.load_module( '_pywrap_tensorflow' , fp, pathname, description)
ImportError: libcudart.so.7.0: cannot  open  shared object  file : No such  file  or directory

   那是你的CUDA安装配置不对:

    安装CUDA和CUDNN可以参考 这篇文章 

  且添加如下两行到你的 ~/.bashrc 文件

1
2
export  LD_LIBRARY_PATH= "$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
export  CUDA_HOME= /usr/local/cuda
  •  如果遇到如下错误:
1
2
3
4
5
6
7
8
9
10
11
12
13
Python  2.7 . 9  (default, Apr   2  2015 15 : 33 : 21 )
[GCC  4.9 . 2 ] on linux2
Type  "help" "copyright" "credits"  or  "license"  for  more information.
>>>  import  tensorflow
I tensorflow / stream_executor / dso_loader.cc: 93 ] Couldn't  open  CUDA library libcublas.so. 7.0 . LD_LIBRARY_PATH: : / usr / local / cuda / lib64
I tensorflow / stream_executor / cuda / cuda_blas.cc: 2188 ] Unable to load cuBLAS DSO.
I tensorflow / stream_executor / dso_loader.cc: 93 ] Couldn't  open  CUDA library libcudnn.so. 6.5 . LD_LIBRARY_PATH: : / usr / local / cuda / lib64
I tensorflow / stream_executor / cuda / cuda_dnn.cc: 1382 ] Unable to load cuDNN DSO
I tensorflow / stream_executor / dso_loader.cc: 93 ] Couldn't  open  CUDA library libcufft.so. 7.0 . LD_LIBRARY_PATH: : / usr / local / cuda / lib64
I tensorflow / stream_executor / cuda / cuda_fft.cc: 343 ] Unable to load cuFFT DSO.
I tensorflow / stream_executor / dso_loader.cc: 101 ] successfully opened CUDA library libcuda.so locally
I tensorflow / stream_executor / dso_loader.cc: 93 ] Couldn't  open  CUDA library libcurand.so. 7.0 . LD_LIBRARY_PATH: : / usr / local / cuda / lib64
I tensorflow / stream_executor / cuda / cuda_rng.cc: 333 ] Unable to load cuRAND DSO.

   由安装报错可知,它使用的是7.0版本,故找不到,而如果你安装的是7.5版本,则可以执行如下命令添加相应链接:

1
2
3
4
sudo  ln  -s  /usr/local/cuda/lib64/libcudart .so.7.5  /usr/local/cuda/lib64/libcudart .so.7.0
sudo  ln  -s libcublas.so.7.5 libcublas.so.7.0
sudo  ln  -s libcudnn.so.4.0.4 libcudnn.so.6.5
sudo  ln  -s libcufft.so libcufft.so.7.0<br> sudo  ln  -s libcurand.so libcurand.so.7.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值