0

As I am using the command prompt to run python when installing tensorflow it is saying requirment satisfied but when importing giving an error

ImportError                               
Traceback (most recent call last)
c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     17         try:
---> 18             fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
     19         except ImportError:

c:\users\chirag\appdata\local\programs\python\python37\lib\imp.py in find_module(name, path)
    295     else:
--> 296         raise ImportError(_ERR_MSG.format(name), name=name)
    297 

ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     57 
---> 58   from tensorflow.python.pywrap_tensorflow_internal import *
     59   from tensorflow.python.pywrap_tensorflow_internal import __version__

c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in <module>
     27             return _mod
---> 28     _pywrap_tensorflow_internal = swig_import_helper()
     29     del swig_import_helper

c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py in swig_import_helper()
     19         except ImportError:
---> 20             import _pywrap_tensorflow_internal
     21             return _pywrap_tensorflow_internal

ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-d6579f534729> in <module>
----> 1 import tensorflow

c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\__init__.py in <module>
     22 
     23 # pylint: disable=g-bad-import-order
---> 24 from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
     25 
     26 try:

c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\__init__.py in <module>
     47 import numpy as np
     48 
---> 49 from tensorflow.python import pywrap_tensorflow
     50 
     51 from tensorflow.python.tools import component_api_helper

c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py in <module>
     72 for some common reasons and solutions.  Include the entire stack trace
     73 above this error message when asking for help.""" % traceback.format_exc()
---> 74   raise ImportError(msg)
     75 
     76 # pylint: enable=wildcard-import,g-import-not-at-top,unused-import,line-too-long

ImportError: Traceback (most recent call last):
  File "c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_pywrap_tensorflow_internal', [dirname(__file__)])
  File "c:\users\chirag\appdata\local\programs\python\python37\lib\imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow_internal'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "c:\users\chirag\appdata\local\programs\python\python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
    import _pywrap_tensorflow_internal
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'


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.
karel
  • 5,489
  • 46
  • 45
  • 50
  • Python 3.7 Doesn't support tensorflow yet, you will need to install python 3.6 – anand_v.singh Feb 08 '19 at 10:46
  • Duplicate of https://stackoverflow.com/questions/54566365/importerror-importing-tensorflow/54566418?noredirect=1#comment95932805_54566418, the question is framed differently there but same solution applies – anand_v.singh Feb 08 '19 at 10:47
  • Possible duplicate of [Fail installation of tensorflow over conda](https://stackoverflow.com/questions/53969443/fail-installation-of-tensorflow-over-conda) – anand_v.singh Feb 08 '19 at 10:48

1 Answers1

0

The TensorFlow build from source on Windows guide mentions it only supports Python 3.5 and Python 3.6.

Last time I installed tensorflow on Windows, if I recall correctly I used Python 3.6.4 64-bit. (I had some errors with Python 3.6.5 but that was last summer so there's a chance slightly newer versions of 3.6 might work). Docs mention:

Requires Python 3.4, 3.5, or 3.6

Because I wanted to install tensorflow-gpu I also had to be mindful of the CUDA Toolkit and CuDNN versions too (some combinations didn't work). Unfortunately I don't remember the CUDA/CuDNN versions 100% but documentation mentions CUDA 9.0 (e.g. Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0

Looking at the nVidia CUDA Archive that's from Sept. 2017 so I would go with a CuDNN version compatible with CUDA 9.0 from around that time from their CuDNN Archive(e.g. 7.0.5 for Windows 10).

Not 100% guaranteed if this will work, but something like this:

  1. Uninstall Python 3.7 (unless you can find a simple way to install multiple version of Python and switch as needed, but doing quick searches reveal it's a bit of a headache on Windows)
  2. Install Python 3.6.4 64 bit
  3. Install pip (if it's not already installed) (download get-pip.py and run it)
  4. Install virtualenv(pip install virtualenv, virtualenv tf-gpu,.\tf-gpu\Scripts\activate) (the point of the virtual environment is to keep a local tensorflow setup as opposed to a global module which might cause headaches with other projects using different TensorFlow dependency versions (numpy,protobuf,six,etc.)
  5. Install CUDA 9.0
  6. Install CuDNN (7.0.5 or wee bit higher, but for CUDA 9.0 for sure)
  7. Reboot, double check Windows Environment Variables for CUDA/CUDNN paths and verify the installs
  8. Finally install TensorFlow with GPU support in the virtual environment:pip install tensorflow-gpu (will take a bit of time: might as well hydrate, etc.)
  9. Hopefully the installation completed successfully in which case verify it: quick test: python -c 'import tensorflow;print("TensorFlow version:",tensorflow.__version__)'...if this doesn't throw errors and prints the version open run the HelloWorld example (which should also print some CUDA info) once the session runs.

If you don't want tensorflow-gpu or don't have a tensorflow compatible GPU you can skip the CUDA/CuDNN part. I still recommend making a virtual environment (e.g. tf-cpu) then use pip install tensorflow instead of pip install tensorflow-gpu within the activated virtual environment.

George Profenza
  • 50,687
  • 19
  • 144
  • 218