简体   繁体   中英

Cannot import tensorflow-gpu in Python

I've installed tensorflow-gpu using conda, before that I've installed CUDA Toolkit 9.0 and CuDNN v7.0 . But after trying to run the hello tensorflow code, I'm facing the following error. It is unable to load lib files.

Following is what I have given as 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

This is the Error after that

   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.

Follow these steps to install Tensorflow using conda

#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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM