tensorflow-gpu 1.9.0 cuda9.0安装

切换cuda版本:参考链接。

修改cuda软连接:

# 参考:https://blog.csdn.net/m0_37400316/article/details/101754957
# 查看之前的软连接
$ stat /usr/local/cuda

# 删除之前的软连接
$ rm /usr/local/cuda # 注意删除的时候current后面不要加 /

# 建立新的软连接
$ sudo ln -s /usr/local/cuda-9.0 /usr/local/cuda

# 查看新的软连接
$ stat /usr/local/cuda
$ ls -l cuda

 

安装tensorflow-gpu 1.9.0,参考:https://blog.csdn.net/davidhopper/article/details/81206673

# 基本上就是在cuda 9.0安装好之后正常安装tensorflow-gpu就好了
# python 3.6环境下安装
# 更新pip
$ pip3.6 --trusted-host=pypi.org --trusted-host=files.pythonhosted.org install --upgrade pip --user

# 安装tensorflow-gpu
pip3.6 --trusted-host=pypi.org --trusted-host=files.pythonhosted.org install tensorflow-gpu==1.9.0 --user

# 安装可能要用的其他包
pip --trusted-host=pypi.org --trusted-host=files.pythonhosted.org install numpy==1.16.4 --user
pip3.6 --trusted-host=pypi.org --trusted-host=files.pythonhosted.org install joblib --user

报错1:

>>> import tensorflow as tf
Traceback (most recent call last):
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in 
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in 
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 1, in 
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/__init__.py", line 22, in 
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 49, in 
    from tensorflow.python import pywrap_tensorflow
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 74, in 
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 58, in 
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in 
    _pywrap_tensorflow_internal = swig_import_helper()
  File "/home/user/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in swig_import_helper
    _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
  File "/usr/lib/python3.6/imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/install_sources#common_installation_problems

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.

解决:参考: https://blog.csdn.net/ksws0292756/article/details/80034086。修改~/.bashrc文件

.bashrc文件截取

export http_proxy="http://10.xxx.xx.xxx:xxxx"
export https_proxy="http://10.xxx.xx.xxx:xxxx"
export PYTHONPATH=/usr/bin/python3:/usr/local/lib

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=/usr/local/lib:/home/user/.local/bin/pip3.6

# for cuda 10.1
# export PATH=/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda-10.1/bin:/home/user/.local/bin/pip3.6
# for cuda 10.1

# for cuda 9.0
export PATH=/home/user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda-9.0/bin:/home/user/.local/bin/pip3.6
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64
export CUDA_HOME=/usr/local/cuda-9.0
# for cuda 9.0

 

警告1:

>>> import tensorflow as tf
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:523: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:524: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/user/.local/lib/python3.6/site-packages/tensorflow/python/framework/dtypes.py:532: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])

解决:参考: https://github.com/tensorflow/tensorflow/issues/31249 @ ymodak 安装指定版本的numpy 1.16.4

# 查看本机numpy版本
$ pip show numpy
Name: numpy
Version: 1.17.3
...

# 卸载该版本
$ pip uninstall numpy

# 安装指定版本
$ pip --trusted-host=pypi.org --trusted-host=files.pythonhosted.org install numpy==1.16.4 --user

 

【python3.7不能安装tensorflow-gpu 1.9.0, 注意: tensorflow-gpu 2.x中没有tf.contrib】

报错:

$ pip3.7 --trusted-host=pypi.org -host=files.pythonhosted.org install tensorflow-gpu==1.9.0 --user
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/, https://pypi.tuna.tsinghua.edu.cn/simpl
ERROR: Could not find a version that satisfies the requirement tensorflow-gpu==1.9.0 (from versions:1.13.2, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 2.0.0a0, 2.0.0b0, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.22.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0)
ERROR: No matching distribution found for tensorflow-gpu==1.9.0

解决:

安装 tensorflow-gpu 1.15.0

$ sudo pip3.7 install tensorflow-gpu==1.15.0

或者 tensorflow-gpu 1.10.0

或者 直接安装2.x版的tensorflow-gpu

$ sudo pip3.7 install --upgrade tensorflow-gpu

pip 20.1.1, Python 3.7.4 

参考:https://www.cnblogs.com/jfdwd/p/11178704.html

 

你可能感兴趣的:(#,DL-基础,Python,#,DL-报错)