A Twizzler
A Twizzler

Reputation: 21

How to fix "ImportError: No module named '_pywrap_tensorflow_internal'"

I was following a deep learning tensorflow tutorial by sentdex here: https://www.youtube.com/watch?v=3zeg7H6cAJw.

I followed the tutorial until I got around here:

#import tools
import gym
import random
import numpy as np
import tflearn
from tflearn.layers.core import input_data, dropout,fully_connected
from tflearn.layers.estimator import regression
from statistics import mean, median
from collections import Counter

#sets the learning rate of the algorithm
LR = 1e-3

#sets up the enviroment and resets it
env = gym.make ('CartPole-v0')
env.reset()

#creates the time goal for the algorithm to solve
goal_steps = 500

#sets the requirement for the original random games
score_requirement

#sets the number of games that are initially played
initial_games = 100


def some_random_games_first():
    for episode in range (5):
        env.reset()
        for t in range(goal_steps):
            env.render()
            action = env.action_space.sample()
            observation, reward, done, info = env.step(action)
            if done:
                break

some_random_games_first()

The code seemed fine until I tried to run it and I got this error:

Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> 
==== RESTART: C:\Python Programs\Deep Learning\Deep Learning Cartpole.py ====
Traceback (most recent call last):
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\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\William\AppData\Local\Programs\Python\Python37-32\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\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\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'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python Programs\Deep Learning\Deep Learning Cartpole.py", line 5, in <module>
    import tflearn
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tflearn\__init__.py", line 4, in <module>
    from . import config
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tflearn\config.py", line 3, in <module>
    import tensorflow as tf
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: disable=unused-import
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\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\William\AppData\Local\Programs\Python\Python37-32\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\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
    from tensorflow.python.pywrap_tensorflow_internal import *
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
    _pywrap_tensorflow_internal = swig_import_helper()
  File "C:\Users\William\AppData\Local\Programs\Python\Python37-32\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.

I have spent hours looking for a solution and have not found any. I am new to the deep learning and tensorflow area, so may you please keep it simple.

Thanks, A Twizzler

Edit: I have installed TFLearn, OpenAI’s gym, and TensorFlow but “pip install tensorflow” did not work so I did “pip install —upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-1.12.0-py3-none-any.whl

Upvotes: 1

Views: 1384

Answers (1)

A Twizzler
A Twizzler

Reputation: 21

I figured out that Python 3.7 was not compatible with the latest version of tensorflow, but it would work if I installed it with Anaconda.

Upvotes: 1

Related Questions