安装pip和virtualenv:
# Ubuntu/Linux 64-bit
sudo apt-get install python-pip python-dev python-virtualenv
创建 Virtualenv 虚拟环境:
virtualenv --system-site-packages tensorflow
激活虚拟环境并安装tensorflow:
对于python27,则执行如下命令:
source ./tensorflow/bin/activate # If using bash
# 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
pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.0.0-cp27-none-linux_x86_64.whl
我装的是1.0的
用的是这个版 本的
tensorflow-1.0.0-cp27-none-linux_x86_64.whl
每个版本的tensorflow对应的cudnn版本也不一样
这个对应用cudnn8.0
测试tensorflow
进入到python中,执行下列代码测试 :
import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
tf.__version__
tf.__path__
配置tensorflow环境
为了避免每次使用tensorflow都要进行activate/deactivate,我在~/.bashrc中最后添加下述命令:. /home/XX/tensorflow/bin/activate
并执行source ~/.bashrc;然后可以成功进入tensorflow环境
退出虚拟环境:
deactivate
配置eclipse编程环境
1 查看tensorflow在虚拟环境中python所在位置
在命令行中输入:
which python
显示:
/home/xx/tensorflow/bin/python
2,在eclipse中配置python解释器
在菜单中,找到
windows->preferences
找到PyDev->Python interpreter
在右边点 New创建一个 新的解释器,取一个新名字
找到路径:在点/home/xx/tensorflow/bin/ 找到python
3,在建立python工程时,选择该解释器即可。
现象:使用eclipse run python程序时,Console中错误提示:
Couldn't open CUDA library libcudnn.so
Couldn't open CUDA library libcufft.so
经过排查,cuda,cudnn均已正确安装,环境变量也正常配置,同时,在系统终端中运行该py文件无报错,于是怀疑是eclipse设置有问题,随即通过如下方式解决:
1.打开Windows->Preferences->PyDev->Interpreters->Python Interpreter
2.选择第二栏选项卡中的Environment,选择new
3.通过new,新建2个Variable,
CUDA_HOME=/usr/local/cuda
LD_LIBRARY_PATH=${CUDA_HOME}:usr/local/cuda/lib64:usr/local/cuda/extras/CUPTI/lib64
*:variable的值根据个人电脑上的配置设定
这个选项其实就是设置eclipse的自定义环境变量
重新运行程序,加载成功。
eclipse中测试tensorflow
进入到python中,执行下列代码测试 :
import tensorflow as tfhello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print sess.run(hello)
a = tf.constant(10)
b = tf.constant(32)
print sess.run(a+b)
print tf.__version__
print tf.__path__