【1.2】tensorflow的安装
安装tensorflow
pip install --upgrade tensorflow
pip install --upgrade tensorflow-gpu
使用的时候:
import tensorflow as tf
报错1:
ImportError: libcublas.so.9.0: cannot open shared object file: no such file or directory.
错误原因:tensorflow 1.6还不支持cuda 9.1 解决办法:重新安装cuda 9.0和cudnn 9.0 cuda旧版本下载地址:https://developer.nvidia.com/cuda-toolkit-archive
cudnn 9.0下载地址:
网络版本的安装(推荐):
wget -c http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-9.0.176-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-9.0.176-1.x86_64.rpm
sudo yum clean all
sudo yum install cuda-9-0
其他方法
sudo rpm -e cuda-repo-rhel7-9-1-local-9.1.85-1.x86_64 #删旧版本
wget -c http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-repo-rhel7-9.0.176-1.x86_64.rpm
sudo rpm -i cuda-repo-rhel7-9.0.176-1.x86_64.rpm
sudo yum clean all
sudo yum install cuda-9.0
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
cuda环境变量添加到bashprofile中
vim .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/cuda/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/
CUDA_HOME=/usr/local/cuda
export PATH
export LD_LIBRARY_PATH
export CUDA_HOME
source .bash_profile
查看nvcc版本号
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85
报错2:
ImportError: libcudnn.so.7: cannot open shared object file: No such file or directory
安装cudnn(需要官网注册:https://developer.nvidia.com/cudnn )
wget -c https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.0.5/prod/9.0_20171129/cudnn-9.0-linux-x64-v7
cp cudnn-9.0-linux-x64-v7.solitairetheme8 cudnn-9.0-linux-x64-v7.tgz
tar -xvf cudnn-9.0-linux-x64-v7.tgz
cp cuda/include/cudnn.h /usr/local/cuda/include
cp cuda/lib64/libcudnn* /usr/local/cuda/lib64 #注意软连接的不要直接拷贝过去,需要在目标文件夹重新建立软连接,否则会报错
报错3:
Illegal instruction (core dumped)
出错原因,高版本不支持
sudo pip uninstall tensorflow
pip install tensorflow==1.5
报错4:
ImportError: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /data/software/anaconda2/lib/python2.7/site-packages/google/protobuf/pyext/_message.so)
vim ~/.bash_profile
在 .bash_profile 文件中添加上面参考论坛中的如下语句:LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH;export LD_LIBRARY_PATH
#cuda
PATH=$PATH:$HOME/bin:/usr/local/cuda/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64/:/usr/local/lib64
CUDA_HOME=/usr/local/cuda
export PATH
export LD_LIBRARY_PATH
export CUDA_HOME
source ~/.bash_profile
就可以解决问题了。
报错5:
ImportError: cannot import name pywrap_tensorflow
1、python误以为tensorflow目录中的tensorflow就是要导入的模块。解决办法,不要在tensorflow中运行python或者ipython
2、The real fix for me was to updated setuptools to the latest and it allowed me to upgrade mock and six to the latest. I was on setuptools 3.3. In my case I also had to remove said modules by hand because they were owned by OS in ‘/usr/local/lib/python2.7/dist-packages/’
check versions of everything
pip freeze | grep -e six -e mock
easy_install --version
Update everything
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
pip install mock --upgrade
pip install six --upgrade
最后就大工告成啦。。。
参考资料:
https://blog.csdn.net/castle_cc/article/details/79861074
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn