how to fix "import keras not working" error - python

I have used Keras remotely, such as on Colab and AWS. Today, I tried to install Keras on my laptop using pip3 install keras, and the message was that keras was already installed on the computer (I must have installed it before):
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Requirement already satisfied: keras in /usr/local/lib/python3.7/site-packages/Keras-2.4.3-py3.7.egg (2.4.3)
Requirement already satisfied: h5py in /usr/local/lib/python3.7/site-packages/h5py-2.10.0-py3.7-macosx-10.15-x86_64.egg (from keras) (2.10.0)
Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.7/site-packages (from keras) (1.16.4)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/site-packages/PyYAML-5.3.1-py3.7-macosx-10.15-x86_64.egg (from keras) (5.3.1)
Requirement already satisfied: scipy>=0.14 in /usr/local/lib/python3.7/site-packages (from keras) (1.2.0)
Requirement already satisfied: six in /usr/local/lib/python3.7/site-packages (from h5py->keras) (1.12.0)
However, when I tried to import keras, I received this message:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3267, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-21-88d96843a926>", line 1, in <module>
import keras
ModuleNotFoundError: No module named 'keras'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 2018, in showtraceback
stb = value._render_traceback_()
AttributeError: 'ModuleNotFoundError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py", line 1095, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py", line 313, in wrapped
return f(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/IPython/core/ultratb.py", line 347, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1502, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 1460, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/inspect.py", line 733, in getmodule
if ismodule(module) and hasattr(module, '__file__'):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 32, in <module>
from tensorflow._api.v1 import app
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/_api/v1/app/__init__.py", line 10, in <module>
from tensorflow.python.platform.app import run
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 23, in <module>
from absl.app import run as _run
ModuleNotFoundError: No module named 'absl'
I Googled to find similar problems and I found some suggestions to try sudo pip3 install keras. Keras was downloaded again. However, when I typed import keras, it still produced errors.
Also, I read this Stack Overflow question: How to fix import keras error with python console, but the solution does not work for me as I am calling a library which calls import keras, so I need the import keras command to work (I can't make it call import tensorflow.keras).
Why is this error happening?
Note: I am using Python 3.7.5. I checked the version of pip through pip --version, getting this message:
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
pip 20.0.2 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
Also, I am running this code in Jupyter Notebook. I have checked that Python 3.7 is being run by Jupyter Notebook.

Try installing tensorflow first:
pip install tensorflow
Then access keras via tensorflow
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import tensorflow as tf

Make sure you're running your script with python3. Macs and some other computers come with Python 2.7 installed as the default for python, which will bamboozle you daily.
If that doesn't work, set up a virtual environment: Using Python 3 in virtualenv

Related

ERROR:root:Internal Python error in the inspect module while installing Tensorflow

I have installed TensorFlow 2.0 with CUDA 10.1, cuDNN SDK = 7.6 and all the different libraries such as pandas, sci-kit learn, Keras, NumPy, Gensim etc. This error is probably due to new TensorFlow version. When I try to confirm it by running this confirmation code. I am getting an error. Kindly help.
import sys
import tensorflow.keras
import pandas as pd
import sklearn as sk
import tensorflow as tf
print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
print(f"Pandas {pd.__version__}")
print(f"Scikit-Learn {sk.__version__}")
print("GPU is", "available" if tf.test.is_gpu_available() else "NOT AVAILABLE")
Error I am getting:
WARNING:tensorflow:From C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\distributions\distribution.py:265: ReparameterizationType.__init__ (from tensorflow.python.ops.distributions.distribution) is deprecated and will be removed after 2019-01-01.
Instructions for updating:
The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use `tfp.distributions` instead of `tf.distributions`.
WARNING:tensorflow:From C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\distributions\bernoulli.py:169: RegisterKL.__init__ (from tensorflow.python.ops.distributions.kullback_leibler) is deprecated and will be removed after 2019-01-01.
Instructions for updating:
The TensorFlow Distributions library has moved to TensorFlow Probability (https://github.com/tensorflow/probability). You should update all references to use `tfp.distributions` instead of `tf.distributions`.
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-1-0b3eb45acbe5>", line 3, in <module>
import tensorflow.keras
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 98, in <module>
from tensorflow_core import *
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2044, in showtraceback
stb = value._render_traceback_()
AttributeError: 'ModuleNotFoundError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 1151, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 319, in wrapped
return f(*args, **kwargs)
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\IPython\core\ultratb.py", line 353, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 1502, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 1460, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\inspect.py", line 733, in getmodule
if ismodule(module) and hasattr(module, '__file__'):
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\__init__.py", line 45, in <module>
from . _api.v2 import compat
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\__init__.py", line 23, in <module>
from . import v1
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\v1\__init__.py", line 40, in <module>
from . import experimental
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\_api\v2\compat\v1\experimental\__init__.py", line 11, in <module>
from tensorflow.python.ops.control_flow_v2_toggles import output_all_intermediates
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\control_flow_v2_toggles.py", line 24, in <module>
from tensorflow.python.ops import control_flow_util_v2
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\control_flow_util_v2.py", line 28, in <module>
from tensorflow.python.keras.engine import base_layer_utils
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\__init__.py", line 27, in <module>
from tensorflow.python.keras import applications
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\applications\__init__.py", line 25, in <module>
from tensorflow.python.keras import engine
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\__init__.py", line 23, in <module>
from tensorflow.python.keras.engine.base_layer import Layer
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 56, in <module>
from tensorflow.python.keras.saving.saved_model import layer_serialization
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\saving\__init__.py", line 20, in <module>
from tensorflow.python.keras.saving.hdf5_format import load_attributes_from_hdf5_group
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\saving\hdf5_format.py", line 32, in <module>
from tensorflow.python.keras.utils import conv_utils
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\utils\__init__.py", line 38, in <module>
from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\utils\multi_gpu_utils.py", line 22, in <module>
from tensorflow.python.keras.engine.training import Model
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 42, in <module>
from tensorflow.python.keras import metrics as metrics_module
File "C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\metrics.py", line 34, in <module>
from tensorflow.python.keras.engine.base_layer import Layer
ImportError: cannot import name 'Layer' from 'tensorflow.python.keras.engine.base_layer' (C:\Users\Abdul\.conda\envs\tensorflow\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py)
---------------------------------------------------------------------------
​
If you get this error on Google colab, then factory reset the runtime. Click on Runtime, then factory reset runtime
If happen in Google Colab:
In top menu click Runtime > Restart Runtime
I solved this issue by downloading and installing
"Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019". It worked for me.
Pre-requisite: Python + Jupyter notebook + tensorflow installation already done
You get this error when you "import tensorflow"
Follow the below steps:
Step 1: Download "Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019 - community edition"
Step 2: Select "Python Workload" while installing Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
Step 3: Restart your computer once
Step 4: That's it now open Jupyter notebook and "import tensorflow" and the error will not occur
I was getting the same error on a Windows 10 VM. Since you're using Anaconda, try:
pip uninstall tensorflow
Then try conda install tensorflow
Then try to import your Keras packages via: from tensorflow.keras.xxx import xxx
As mentioned in the comments above, it might be worth a try setting up a virtual environment in conda, and installing the required packages there.
In Anaconda you cannot see the pip uninstall prompts you with "Do you want to continue (Y/N)? Therefore you should add --yes: pip uninstall tensorflow --yes

"ModuleNotFoundError: No module named 'bootstrap4' " occured when deploying django project to PythonAnywhere

I'm trying to deploy my django project to PythonAnywhere referring to https://tutorial.djangogirls.org/en/deploy/.
When I executed this command,
pa_autoconfigure_django.py --python=3.6 https://github.com/my_git_url.git
The following error happened: (actually some texts are omitted because it's long)
Traceback (most recent call last):
File "/home/kanchi0914/kanchi0914.pythonanywhere.com/manage.py", line 21, in <module>
main()
File "/home/kanchi0914/kanchi0914.pythonanywhere.com/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/home/kanchi0914/.virtualenvs/kanchi0914.pythonanywhere.com/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bootstrap4'
Traceback (most recent call last):
File "/home/kanchi0914/.local/bin/pa_autoconfigure_django.py", line 52, in <module>
django-bootstrap4andbootstrap4 seems to be correctlly installed.
23:45 ~ $ pip3.6 install --user django-bootstrap4
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: django-bootstrap4 in ./.local/lib/python3.6/site-packages (1.0.1)
Requirement already satisfied: beautifulsoup4 in /usr/lib/python3.6/site-packages (from django-bootstrap4) (4.6.0)
I guessed these sites would be useful, tried some solutions, but situation did not change.
https://www.tangowithdjango.com/book17/chapters/deploy.html
https://www.pythonanywhere.com/forums/topic/12404/
Off cource I confirmed my project work well in my local env.
What should I do?
thanks.
I had this one time. Maybe you have to use pip3 if you are using python 3. Or pip if you are using python 2. Packages installed with pip3 won't work in python 2 and vice versa if your python version is 2. Not sure if this helps.

How to Correctly Install Tensorflow on Windows x64-bit Python 3.6.x [duplicate]

This question already has answers here:
Issue installing Tensorflow -- not a CUDA/CuDNN issue
(4 answers)
Closed 4 years ago.
When I first used $ pip install --upgrade tensorflow, I was unable to install it. After looking around on multiple sites, I realized that it was because I had installed the x32-bit version of Python, not the x64-bit. After uninstalling the old Python and installing the new one, I was able to install tensorflow. This was the output:
C:\Users\Seth>pip install --upgrade tensorflow --user
Collecting tensorflow
Using cached https://files.pythonhosted.org/packages/0e/2a/c3fe6035f0a8726e5b210680af3ccaf826f4a64ce7306e57017aba749447/tensorflow-1.10.0-cp36-cp36m-win_amd64.whl
Collecting six>=1.10.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting absl-py>=0.1.6 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/a7/86/67f55488ec68982270142c340cd23cd2408835dc4b24bd1d1f1e114f24c3/absl-py-0.4.1.tar.gz
Collecting gast>=0.2.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/5c/78/ff794fcae2ce8aa6323e789d1f8b3b7765f601e7702726f430e814822b96/gast-0.2.0.tar.gz
Requirement already satisfied, skipping upgrade: setuptools<=39.1.0 in c:\program files (x86)\microsoft visual studio\shared\python36_64\lib\site-packages (from tensorflow) (39.0.1)
Collecting wheel>=0.26 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl
Collecting protobuf>=3.6.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/e8/df/d606d07cff0fc8d22abcc54006c0247002d11a7f2d218eb008d48e76851d/protobuf-3.6.1-cp36-cp36m-win_amd64.whl
Collecting astor>=0.6.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
Collecting tensorboard<1.11.0,>=1.10.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/c6/17/ecd918a004f297955c30b4fffbea100b1606c225dbf0443264012773c3ff/tensorboard-1.10.0-py3-none-any.whl
Collecting grpcio>=1.8.6 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/65/da/03e722b7981ab3222f292f735a3c157b1d1bca120c479d7e273273828170/grpcio-1.14.2-cp36-cp36m-win_amd64.whl
Collecting termcolor>=1.1.0 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Collecting numpy<=1.14.5,>=1.13.3 (from tensorflow)
Using cached https://files.pythonhosted.org/packages/0d/b7/0c804e0bcba6505f8392d042d5e333a5e06f308e019517111fbc7767a0bc/numpy-1.14.5-cp36-none-win_amd64.whl
Collecting markdown>=2.6.8 (from tensorboard<1.11.0,>=1.10.0->tensorflow)
Using cached https://files.pythonhosted.org/packages/6d/7d/488b90f470b96531a3f5788cf12a93332f543dbab13c423a5e7ce96a0493/Markdown-2.6.11-py2.py3-none-any.whl
Collecting werkzeug>=0.11.10 (from tensorboard<1.11.0,>=1.10.0->tensorflow)
Using cached https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl
Installing collected packages: six, absl-py, gast, wheel, protobuf, astor, numpy, markdown, werkzeug, tensorboard, grpcio, termcolor, tensorflow
Running setup.py install for absl-py ... done
Running setup.py install for gast ... done
The script wheel.exe is installed in 'C:\Users\Seth\AppData\Roaming\Python\Python36\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
The script markdown_py.exe is installed in 'C:\Users\Seth\AppData\Roaming\Python\Python36\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
The script tensorboard.exe is installed in 'C:\Users\Seth\AppData\Roaming\Python\Python36\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Running setup.py install for termcolor ... done
The scripts freeze_graph.exe, saved_model_cli.exe, tensorboard.exe, tflite_convert.exe, toco.exe and toco_from_protos.exe are installed in 'C:\Users\Seth\AppData\Roaming\Python\Python36\Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed absl-py-0.4.1 astor-0.7.1 gast-0.2.0 grpcio-1.14.2 markdown-2.6.11 numpy-1.14.5 protobuf-3.6.1 six-1.11.0 tensorboard-1.10.0 tensorflow-1.10.0 termcolor-1.1.0 werkzeug-0.14.1 wheel-0.31.1
I thought it had worked until I imported it in a program. This was the result of that:
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\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 "<pyshell#3>", line 1, in <module>
import tensorflow as tf
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\__init__.py", line 22, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Seth\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\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.
What did I do wrong?
Download Anaconda. It comes with installed tensorflow and other libraries. Check out this website
SOLUTION
Thank you P-Gn for marking this as a duplicate. I would not have found the answer otherwise. Tensorflow works in version 1.5 for me, but I will probably have to find a way to get 1.10 working.

Difficulty in getting Tensorflow to work [duplicate]

I recently started getting into Tensorflow, but i'm having issues with the install. Everytime I try to import it I get the following error
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\[user]\AppData\Local\Programs\Python\Python36\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.
I looked at other stack overflow posts that were having the same problem as me, and they suggested getting the CUDA libraries from NVIDIA. The problem is, I have neither a NVIDIA graphics card nor the GPU version of tensorflow, so I don't think that's the issue. There were also suggestions to make sure the Microsoft redistributables for visual studio are installed, which they are.
If this is a system variable based problem, I'd appreciate help with changing system variables as I'm new to doing that. Thank you!
Some System Info:
OS: Microsoft Windows 10 Pro Version 10.0.17134
CPU: Intel Xeon E5620
Graphics Card: Radeon RX 480
Python Version: 3.6.5 amd64 Tensorflow
Install method: pip install tensorflow
#user1735003 figured it out.
I unistalled the latest version of tensorflow
pip uninstall tensorflow
and then installed tensorflow 1.5
pip install tensorflow==1.5
then I verified the installation worked with the script
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
I got the correct output
Hello, TensorFlow!
My guess is that you are trying to use TF >= 1.6, because your CPU is rather old and does not support AVX instructions. Indeed from 1.6 on, tensorflow pre-built binaries use AVX instructions.
Currently your options are either to:
Use an official pre-built binary of TF 1.5 or earlier. (You will miss a few things but it's still OK I would say).
Search for an unofficial pre-built binary of TF >= 1.6 that does not support AVX.
Currently, pre-built binaries until TF 1.10 from conda install on Windows seem not to be built with AVX support, although I could not find this information anywhere and therefore cannot tell if this is intentional and how long that will be the case.
Beware that binaries from conda-forge (which used to be the main conda tensorflow provider before it has been available on the main channel) on the other hand are built with AVX support.
Change your hardware to support AVX (obviously).
Compile your own binary of tensorflow without AVX instructions. A reasonable option if none of the others were possible.
Have in mind that the above answers are correct for a lot of cases.
However, downgrading to tensorflow 1.5 might not be the best solution because for instance, you won't have access to some of the new features of tensorflow like the 'eager execution' feature for example.
What i did in my case was to install tensorflow 1.8 with conda instead of pip. From my little experience with conda and pip, conda seems to perform better when it comes to placing required files in their proper location.
In summary,
Instead of pip3 install --upgrade tensorflow,
i used conda install tensorflow which will install the latest version properly.
In case you don't have Anaconda installed for conda commands. Download from here
If the problem persists check the version numbering and make sure cuda and TF are compatible.
Check the version numbering here
or for a simpler way, use Anaconda
conda create --name new_env_name tensorflow-gpu
activate new_env_name
I successfully installed TensorFlow GPU version 1.12 (latest until the date of writing) with Cuda 9.0, GeForce 1050 Ti, Windows 10 and Python 3.6.7
Note: You have installed the CUDA Toolkit (version 9) for TensorFlow to recognize your GPU

python tensorflow import dll load failed

I installed latest python 3.6.4 x64 version
and then installed tensorflow for cpu-only with pip3
C:\>pip3 install tensorflow
however when I tried to import tensorflow in python
it showed me the error below
I am sure that I have installed Microsoft Visual C++ 2015 Redistributable(x64)
so it wll not be the problem of dll msvcp140.dll lost
it say that "DLL load failed with error code -1073741795"
so what is exactly the problem here
i cannot find any other information about this error code
my os : windows 7 enterprise with service pack 1 / 64 bit / intel core i5 M 540
>>> import tensorflow
Traceback (most recent call last):
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\importlib\__ini
t__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\importlib\__ini
t__.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\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\importlib\__ini
t__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\site-packages\t
ensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\Alan\AppData\Local\Programs\Python\Python36\lib\importlib\__ini
t__.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_probl
ems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I got same problem with tensorflow1.6-CPU on win7 64bit(Intel Core 2 Duo Cpu T6670 2.2GHz)
After I found this, and it solved my problem.
Reference this issue: https://github.com/tensorflow/tensorflow/issues/17386
Re-installed by this tensorflow-1.6.0-cp36-cp36m-win_amd64.whl: https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.6.0/py36/CPU/sse2
Hope this .whl may help you.
I faced the same issue with tensorflow-1.12.0
what i did was :
Install anaconda
open anaconda prompt
conda create -n tfp python=3.6
activate tfp
conda install tensorflow
python
Now check by importing tensorflow
the version i used was 3.6, but you can also try with 3.7
Hope it helps!
I downgraded tensorflow to 1.10.0 and it fixed the issue
Probably, your CPU does not have the instructions for AVX (needed for all tensorflow binaries since 1.6). You can check that with some tool like CPU-Z. If that is the case, you can donwload the correct wheel here (use SSE2 binaries):
tensorflow-windows-wheel
I had the same issue.
I upgraded pip version with:
python -m pip install --upgrade pip
also, downgraded with
pip install tensorflow==2.0
and it worked
ImportError: DLL load failed
for
windows 10
python 3.6
pip install protobuf==3.6.0
or
pip3 install protobuf==3.6.0
I fixed it.
Spend days searching to fix them.
Installed tensorflow with pip install tensorflow-cpu
Updated visual C++ 2015-2019
The issue was because I didn't have nvidia graphics so that I should install with cpu version because I am using Radeon Vega 8 graphics.
Hope it helps.
I have tried different methods still it doesn't work then I apply this method it works for me.
STOP you antivirus protection software for half hour then install anaconda,it works fine. 100%
If you use python 3.6.10 and tensorflow 2.1.0
Just follow this -
pip install tensorflow==2.0
It worked for me.
I had first Upgraded the Anaconda prompt
I had then used conda create -n tfp python=3.7
conda activate tfp
Then import the tensorflow
I faced the similar issue for tensorflow 2.0
First I uninstalled tensorflow using pip uninstall tensorflow (no need to uninstall tensorflow-estimator or tensorboard).
Then I reinstall using conda install tensorflow.
Never install the latest version of tensorflow it will raise an error
DLL file load error
pip install tensorflow
never run command on your computer as it not supports the tensorflow cpu
most of the latest version supports mostly gpu
so while installing install the lower version of the tensorflow
from my opininon the stable release of tensorflow is tensorflow 1.5
make sure you uninstalled your tensorflow installed in your computer
pip uninstall tensorflow
After above step shutdown your pc and restart.Then only install tensorflow 1.5
command to install tensorflow version 1.5
pip install tensorflow==1.5
Install Microsoft Visual C++ 2019 Redistributable & reboot the PC, it will work with tensorflow 2.3.1 in python 3.7

Categories