我在Spyder(Anaconda)中的ipython控制台未选择正确的Windows的系统PATH环境变量

时间:2018-11-30 18:13:49

标签: python tensorflow anaconda ipython spyder

首先,最原始的问题源于我尝试安装Tensorflow GPU的问题。

首先,我首先安装所有依赖的软件包(Nvidia GPU驱动程序,CUDA,cudnn等),一个新的Anaconda软件包和tensorflow-gpu。到目前为止一切都很好。

然后,我启动了Spyden IDE,并尝试在ipython中运行“ import tensorflow”。然后我得到了这个错误:

Traceback (most recent call last):

  File "<ipython-input-1-d6579f534729>", line 1, in <module>
    import tensorflow

  File "C:\Users\zhengxin\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import

  File "C:\Users\zhengxin\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow

  File "C:\Users\zhengxin\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)

ImportError: Traceback (most recent call last):
  File "C:\Users\zhengxin\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\zhengxin\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\zhengxin\Anaconda3\lib\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 "C:\Users\zhengxin\Anaconda3\lib\imp.py", line 243, in load_module
    return load_dynamic(name, filename, file)
  File "C:\Users\zhengxin\Anaconda3\lib\imp.py", line 343, in load_dynamic
    return _load(spec)
ImportError: DLL load failed: The specified module could not be found.


Failed to load the native TensorFlow runtime.

See https://www.tensorflow.org/install/errors

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

然后,我进行了大量研究,发现造成此错误的最可能原因是以下两个路径不在Spyder(ipython)中显示的PATH环境变量中。

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp

非常奇怪的是,这两个路径确实存在于Windows的系统PATH环境变量中。

所以,最后,我的问题是,为什么Spyder / ipython / anaconda不选择Windows的PATH环境变量?

1 个答案:

答案 0 :(得分:1)

好的,我已经解决了这个问题。

缺少PATH环境变量的事实是真实的事实,但实际上仅仅是tensorflow-gpu依赖关系设置错误的症状。

最终,问题出在我安装了CUDA 10.0及其随附的cuDNN。 10.0版是NVIDIA网站上的最新版本,对于人们来说,这是很自然的错误!无论如何,然后我通读了CUDA和TensorFlow的发行说明,并确定我必须安装CUDA 9.0。那行得通!

最令人惊讶和奇怪的是,一旦我安装了CUDA 9.0,所有环境变量突然都变得正确了!即,这四个目录的路径环境变量突然间全部出现,就像魔术一样,出现在我的ipython / anaconda / spyder的PATH变量中!

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\libnvvp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\libnvvp