【问题标题】:Cannot import tensorflow-gpu in Python无法在 Python 中导入 tensorflow-gpu
【发布时间】:2017-08-29 09:26:49
【问题描述】:

我已经使用 conda 安装了 tensorflow-gpu,在此之前我已经安装了 CUDA Toolkit 9.0 和 CuDNN v7.0。但是在尝试运行 hello tensorflow 代码后,我遇到了以下错误。无法加载 lib 文件。

以下是我作为 I/p 给出的内容:

Microsoft Windows [Version 10.0.15063]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\Manish>activate tensorflow-gpu

(tensorflow-gpu) C:\Users\Manish>python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf

这是之后的错误

   Traceback (most recent call last):
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
        return importlib.import_module(mname)
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 978, in _gcd_import
      File "<frozen importlib._bootstrap>", line 961, in _find_and_load
      File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 560, in module_from_spec
      File "<frozen importlib._bootstrap_external>", line 922, in create_module
      File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
    ImportError: DLL load failed: The specified module could not be found.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
        return importlib.import_module('_pywrap_tensorflow_internal')
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
        from tensorflow.python import *
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
        from tensorflow.python import pywrap_tensorflow
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
        raise ImportError(msg)
    ImportError: Traceback (most recent call last):
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
        return importlib.import_module(mname)
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 978, in _gcd_import
      File "<frozen importlib._bootstrap>", line 961, in _find_and_load
      File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 648, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 560, in module_from_spec
      File "<frozen importlib._bootstrap_external>", line 922, in create_module
      File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
    ImportError: DLL load failed: The specified module could not be found.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
        from tensorflow.python.pywrap_tensorflow_internal import *
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
        _pywrap_tensorflow_internal = swig_import_helper()
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
        return importlib.import_module('_pywrap_tensorflow_internal')
      File "C:\Users\Manish\Anaconda3\envs\tensorflow-gpu\lib\importlib\__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


    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.

【问题讨论】:

  • 你应该格式化你的帖子不清楚
  • @Ivan 我已经完成了格式化
  • @Ivan 我终于完成了格式化
  • 抱歉,它要求我添加更多详细信息,否则无法保存
  • 最后忽略那些IIIIIIIII

标签: python tensorflow cmd conda tensorflow-gpu


【解决方案1】:

按照以下步骤使用 conda 安装 Tensorflow

#Set Up Anaconda Environments
conda create --name tf_gpu python=3

#Activate the new Environment
source activate tf_gpu

# Install CUDA and cuDNN
tf_gpu$conda install -c anaconda cudatoolkit=9.0 cudnn=7.0

#Install Tensorflow
tf_gpu$ conda install -c anaconda tensorflow-gpu

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 2019-05-17
    • 2023-04-11
    • 1970-01-01
    • 2017-09-20
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多