Tensorflow not running on windows and pycharm - python

I´m trying to make my first try with Tensorflow using windows 8.1 and Pycharm but I get an Tensorflow error.
I also installed everything in a virtual env with pip and runned the code in the command line with the same result.
Some things I tried
I read other posts relating the issue to the msvcp140.dll and I do have the C++ distributable installed.
Also found info related to downgrading to python 3.5. I actually use Python 3.7 and wouldn´t like to downgrade. I´m worried other apps won´t work. Can anyone confirm it won´t work with Python greater than 3.5?
Also read info about using Conda, but a the same time other info saying to avoid it, naming pip as the officialy supported method.
Also found info about my Intel® Pentium® Processor B980 not supporting AVX instructions. Is this a must when using CPU or only when using the GPU?
Any clues? Thanks in advance!
The following is the error message I get:
Using TensorFlow backend.
Traceback (most recent call last): File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in
from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\imp.py", line 243, in
load_module
return load_dynamic(name, filename, file) File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\imp.py", line 343, in
load_dynamic
return _load(spec) ImportError: DLL load failed: No se puede encontrar el módulo especificado.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:/Users/Lia
love/TestAi/Test1.py", line 4, in
from keras.models import Sequential File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\keras__init__.py",
line 3, in
from . import utils File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\utils__init__.py",
line 6, in
from . import conv_utils File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\utils\conv_utils.py",
line 9, in
from .. import backend as K File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\backend__init__.py",
line 89, in
from .tensorflow_backend import * File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\backend\tensorflow_backend.py",
line 5, in
import tensorflow as tf File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow__init__.py",
line 24, in
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python__init__.py",
line 49, in
from tensorflow.python import pywrap_tensorflow File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 74, in
raise ImportError(msg) ImportError: Traceback (most recent call last): File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 58, in
from tensorflow.python.pywrap_tensorflow_internal import * File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 28, in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py",
line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "C:\Users\Lia
love\AppData\Local\Programs\Python\Python37\lib\imp.py", line 243, in
load_module
return load_dynamic(name, filename, file) File "C:\Users\Lia love\AppData\Local\Programs\Python\Python37\lib\imp.py", line 343, in
load_dynamic
return _load(spec) ImportError: DLL load failed: No se puede encontrar el módulo especificado.
Failed to load the native TensorFlow runtime.
Test code
I estimate this is not a problem about my code, but I include it just in case.
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from keras.models import Sequential
from keras.layers import Dense
df = pd.read_csv("housepricedata.csv")
dataset = df.values
X = dataset[:, 0:10]
Y = dataset[:, 10]
min_max_scaler = preprocessing.MinMaxScaler()
X_scale = min_max_scaler.fit_transform(X)
X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X_scale, Y, test_size=0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size=0.5)
print("Keras model setup")
model = Sequential([
Dense(32, activation='relu', input_shape=(10,)),
Dense(32, activation='relu'),
Dense(1, activation='sigmoid'),
])

Intel Pentium processors do not support Advanced Vector Instructions ( AVX ) which are needed by TensorFlow if installed from PyPI through :
pip install tensorflow
Since, your CPU doesn't support AVX, you have two options to choose from:
Use Anaconda
Anaconda uses conda distribution index which is similar to PyPI. The TensorFlow conda build uses MKL ( Intel Math Kernel Library ). It works without AVX.
Download Anaconda as mentioned here and create a new conda enviroment as mentioned here. Run this command:
conda install tensorflow
Use builds from tensorflow-windows-wheel repo.
This repo contains a number of TensorFlow pip wheel files which are build using SSE instead of AVX. SSE build run without any compilation errors. Use this file from the repo.
Hope this helps.

Python virtual environments are used to isolate package installation from the system (recommended)
Make sure these installation:
python3 --version
pip3 --version
virtualenv --version
Create a new virtual environment by choosing a Python interpreter and making a .\venv directory to hold it:
virtualenv --system-site-packages -p python3 ./venv
Activate the virtual environment:
.\venv\Scripts\activate
Install packages within a virtual environment without affecting the host system setup. Start by upgrading pip:
pip install --upgrade pip
pip list # show packages installed within the virtual environment
pip install --upgrade tensorflow
#Verify the install:
python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
Open your project in pycharm and go to project setting and change the python run time to target this virtual env.
Hope this will help.

Related

ModuleNotFoundError: No module named 'keras.api' error

I am trying to run a ".py" file on windows 10 with tensorflow version 2.8.0 and keras version 2.3.4, where I am calling libraries as follows
from tensorflow import keras
from keras.models import load_model
However, I am getting an error message "ModuleNotFoundError: No module named 'keras.api'"
as shown in the error log below.
DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
from distutils.log import debug
Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\saniy\OneDrive\Derma-Project\app1.py", line 5, in <module>
from keras.models import load_model
File "C:\Python310\lib\site-packages\keras\__init__.py", line 3, in <module>
from . import utils
File "C:\Python310\lib\site-packages\keras\utils\__init__.py", line 26, in <module>
from .vis_utils import model_to_dot
File "C:\Python310\lib\site-packages\keras\utils\vis_utils.py", line 7, in <module>
from ..models import Model
File "C:\Python310\lib\site-packages\keras\models.py", line 12, in <module>
from .engine.training import Model
File "C:\Python310\lib\site-packages\keras\engine\__init__.py", line 8, in <module>
from .training import Model
File "C:\Python310\lib\site-packages\keras\engine\training.py", line 14, in <module>
from . import training_utils
File "C:\Python310\lib\site-packages\keras\engine\training_utils.py", line 17, in <module>
from .. import metrics as metrics_module
File "C:\Python310\lib\site-packages\keras\metrics.py", line 1850, in <module>
BaseMeanIoU = tf.keras.metrics.MeanIoU
File "C:\Python310\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 58, in __getattr__
module = self._load()
File "C:\Python310\lib\site-packages\tensorflow\python\util\lazy_loader.py", line 41, in _load
module = importlib.import_module(self.__name__)
File "C:\Python310\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'keras.api'
I am wondering if you can help in this regard.
I am not sure how keras 2.3.4 is installed but minimum version of keras for tf 2.8 is 2.8; Just upgrade your keras version
pip install keras==2.8
Since version 2 of Tensorflow (TF), the Keras package comes installed alongside. Meaning that if you make pip install tensorflow, will install the latest TF version (2.8) and Keras 2.8. As the other answer suggests, I would guess you have some old Keras version installed on your computer.
My advise would be to create a fresh virtual environment,
python3 -m venv ENV_DIR
and then freshly install all the requirements that your .py file needs from scratch. This will hopefully solve your issue and it is also best practice not to mess with different Python packages versions throughout your projects.

Can't import tensorflow when run script from terminal, even though tensorflow works in jupyter notebook and terminal

TLDR: When I write a small script named toy_model.py and attempt to run it from the command line with
py toy_model.py
I get an error message complaining about loading tensorflow.
However, I am able to use import and use tensorflow in many other settings without any problem, such as
In a jupyter notebook
when I import toy_model.py into a jupyter notebook
when I use python from the command line
I have tried many recommended solutions (downloading Spyder in the Anaconda Navigator virtual environment I am using, switching from tensorflow 2.1.0 to tensorflow 2.0.0, downloading microsoft visual studio), and none have been succesful.
I would be grateful for any assistance or insight into this problem, which I will describe in more detail below.
I use Anaconda Navigator to code in Python. In Anaconda Navigator, I prepared an environment with the name updated_tensorflow. I used Anaconda's package manager to download tensorflow 2.0.0 and keras 2.3.1 into this environment.
I prepared a jupyter notebook named test1.ipynb with the following code:
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(10,))])
model.compile(optimizer='adam',
loss= 'sparse_categorical_crossentropy', #should be 'sparse_categorical_crossentropy' b/c one-hot encoded
metrics=['accuracy'])
model.predict([[1,2,3,4,5,6,7,8,9,10], [-1,2,-3,4,-5,6,-7,8,-9,10]])
When I run test1.ipynb from the environment updated_tensorflow, there are no problems.
In the terminal I entered the environment updated_tensorflow, and began using python by typing python in the command line. I entered the same code as in test1.ipynb and had no problems.
I create a file with the name toy_model.py that contained the following code:
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(10,))])
model.compile(optimizer='adam',
loss= 'sparse_categorical_crossentropy', #should be 'sparse_categorical_crossentropy' b/c one-hot encoded
metrics=['accuracy'])
Then, I created another jupyter notebook in the same directory as toy_model1.py with the name test2.ipynb and the following code:
from toy_model1 import *
model.predict([[1,2,3,4,5,6,7,8,9,10], [-1,2,-3,4,-5,6,-7,8,-9,10]])
This cell ran with no problems.
Finally, in this same directory, I produced a small file with the name toy_model.py which contained the code
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import keras
model = tf.keras.Sequential([
tf.keras.layers.Dense(1, input_shape=(10,))])
model.compile(optimizer='adam',
loss= 'sparse_categorical_crossentropy', #should be 'sparse_categorical_crossentropy' b/c one-hot encoded
metrics=['accuracy'])
model.predict([[1,2,3,4,5,6,7,8,9,10], [-1,2,-3,4,-5,6,-7,8,-9,10]])
Then in my terminal, still in the environment updated_tensorflow, I moved to the directory containing toy_model.py and attempted to run it with
py toy_model.py
I got the following message that indicated I could not import tensorflow:
Traceback (most recent call last):
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\me\Anaconda3\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\me\Anaconda3\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
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 "toy_model.py", line 3, in <module>
import tensorflow as tf
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 50, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 69, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\me\Anaconda3\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\me\Anaconda3\Anaconda3\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\me\Anaconda3\Anaconda3\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
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.
Some of the advice I have followed in my unsuccessful efforts to fix this problem includes:
making sure pip and setup tools are updated
uninstalling and reinstalling tensorflow and keras using pip
uninstalling and reinstalling tensorflow and keras using conda
switching from tensorflow 2.1.0 to tensorflow to 2.0.0
installing tensorflow and keras on my base anaconda environment
installing tensorflow and keras on my machine
downloading Spyder in my updated_tensorflow environment
downloading Microsoft visual studios
None have been successful.
I would be very grateful for any assistance in understanding and fixing whatever error I am making. It would be so nice if I could use run .py files from my terminal instead of using python exclusively in Jupyter notebooks!
Even a hint as to what the error message means would be helpful: I do not properly understand what a DLL even is.
It sounds like, by invoking python, you are not getting the specific python installation that has tensorflow (or tensorflow in that installation is broken). By default, invoking python will give you the system default (it's the first one in the environment path, so that's the first hit).
I would advise identifying exactly which python interpreter your notebook is using and calling that one specifically by saying
/path/to/notebook/interpreter/python toy_model.py
Try to get the latest supported Microsoft Visual C++

ImportError: DLL load failed: The specified module could not be found.(Keras)

First I have created an environment in anaconda navigator in which i have installed packages like Keras,Tensorflow and Theano.
Now I have activated my environment through anaconda navigator and have launched the Spyder Application.
Now When i try to import keras it is showing error stating that:
Traceback (most recent call last):
File "C:\Users\Quickhotshot612\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\Quickhotshot612\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\Quickhotshot612\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Users\Quickhotshot612\Anaconda3\envs\tensorflow\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Users\Quickhotshot612\Anaconda3\envs\tensorflow\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified module could not be found.
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.
And is continuously the showing the error like an infinite.
Where did i go wrong? Anyone help me with this.enter image description here
But when i give (import theano),it is working,but does'nt in the case of tensorflow and keras.
Yes,I kinda figured out and it works for me!
1)Check pip,setuptools and wheel are up to date.
2)If u get an error during installation with the wrapt library."conda remove wrapt" and then "pip install tensorflow"
3)Also u should have the Microsoft Visual C++ Redistributable for Visual Stuido 2015 installed in your computer or a higher version.
4)Then try to import tensorflow or tensorflow.keras
If this still shows ImportError. Open the navigator and and install tensorflow from there directly by selecting that environment and going to Not installed and then search for tensorflow and download the package.It will automatically add the package to your environment and open say spyder and try to import tensorflow in kernal.
This works fine.
Even if u have a pip error i.e cannot import name 'Flowcontrol', U can try this method.
Peace!!
I solved the issue by downgrade tensorflow to version 2.0
pip install --user tensorflow==2.0
per Github enter link description here
My platform:
win10
python 3.7
tensorflow 2.1

Tensorflow 2.1.0 - DLL load failed - windows cpu

Installation of TensorFlow 2.1.0 was successful, but TensorFlow import failed.
Open question:
Is there a library that is in a different location/not installed on the system that cannot be loaded?
Procedure for reproduction:
1) create environment
conda create --name tensorflow21_env
2) activate environment
conda activate tensorflow21_env
3) install
conda install python=3.7
pip install tensorflow-cpu #install tensorflow=2.1.0;
4) test
python -c "import tensorflow as tf"
Stacktrace:
Traceback (most recent call last):
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 342, in load_dynamic
return _load(spec)
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 "<string>", line 1, in <module>
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 101, in <module>
from tensorflow_core import *
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\Anaconda3\envs\tensorflow21_env\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Anaconda3\envs\tensorflow21_env\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description)
File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "C:\Anaconda3\envs\tensorflow21_env\lib\imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
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.
Installation Output:
Output: conda install python=3.7
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: C:\Anaconda3\envs\tensorflow21_env
added / updated specs:
- python=3.7
The following NEW packages will be INSTALLED:
ca-certificates pkgs/main/win-64::ca-certificates-2020.1.1-0
certifi pkgs/main/win-64::certifi-2019.11.28-py37_0
openssl pkgs/main/win-64::openssl-1.1.1d-he774522_4
pip pkgs/main/win-64::pip-20.0.2-py37_1
python pkgs/main/win-64::python-3.7.6-h60c2a47_2
setuptools pkgs/main/win-64::setuptools-45.2.0-py37_0
sqlite pkgs/main/win-64::sqlite-3.31.1-he774522_0
vc pkgs/main/win-64::vc-14.1-h0510ff6_4
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.16.27012-hf0eaf9b_1
wheel pkgs/main/win-64::wheel-0.34.2-py37_0
wincertstore pkgs/main/win-64::wincertstore-0.2-py37_0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
The dependency walker confirms that all DLLs could be loaded (download dependency walker).
dependency_trace
Addon:
path for dependency walker
C:\Anaconda3\envs\tensorflow21_env\Lib\site-packages\tensorflow_core\python\_pywrap_tensorflow_internal.pyd
Update:
My processor supports neither AVX nor AVX2 and therefore the tensorflow pip package could not be installed or to be more precise the tensorflow package could not be imported.
Interim solution:
The interim solution for legacy & low-end CPU without AVX support is to install SSE-prebuild-binaries for tensorflow.
Go to tensorflow-windows-wheel and follow instruction to install either tensorflow 2.0.0 or 2.1.0.
Try this method:
Uninstall the TensorFlow package that you installed using pip and reinstall using conda install tensorflow this may work! Now you can import TensorFlow without problems. I hope this can help you.
If you need more detailed steps. Here, you can do the following below.
Run the anaconda prompt as an administrator. (right click-> run as administrator).
pip uninstall tensorflow
Close anaconda prompt.
Again run anaconda prompt as administrator.
type:
conda install tensorflow
It will ask for some y / n
Type y.
Now after all done, change your python interpreter's environment to anaconda environment where you installed tensorflow.
Now try importing tensorflow.
I hope this helps.

Tensorflow installation issue: ImportError: DLL load failed with error code -1073741795

I am unable to install and import Tensorflow on my PC. I have tried the below approach as mentioned on https://www.tensorflow.org/install/pip#package-location. I have also tried installation using Conda but the same problem appears. MS Visual C++ is also installed as mentioned on https://www.tensorflow.org/install/pip#package-location
System information
OS Platform: Windows 7 Service Pack1 TensorFlow installed from (source
or binary):
https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.12.0-cp35-cp35m-win_amd64.whl
TensorFlow version: 1.12 Python version: 3.5.4 64-bit Installed using
virtualenv
Traceback (most recent call last):
File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in from
tensorflow.python.pywrap_tensorflow_internal import * File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28,
in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24,
in swig_i mport_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript ion) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 243, in load_module return load_dynamic(name, filename,
file) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 343, in load_dynamic return _load(spec) ImportError: DLL
load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "", line 1, in File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow_init_.py", line 24, in from tensorflow.python
import pywrap_tensorflow # pylint: disable=unused-im port File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python_init_.py", line 49, in from
tensorflow.python import pywrap_tensorflow File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
raise ImportError(msg) ImportError: Traceback (most recent call last):
File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in from
tensorflow.python.pywrap_tensorflow_internal import * File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 28,
in
_pywrap_tensorflow_internal = swig_import_helper() File "C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\si
te-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 24,
in swig_i mport_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, descript ion) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 243, in load_module return load_dynamic(name, filename,
file) File
"C:\Users\Desk\AppData\Local\Programs\Python\Python35\Scripts\venv\lib\im
p.py", line 343, in load_dynamic return _load(spec) ImportError: DLL
load failed with error code -1073741795
If your CPU didn't support AVX instructions, you will get ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed. (Win 10) or ImportError: DLL load failed with error code -1073741795 (Win 7) when using tensorflow official release 1.6.0 and up (pip install tensorflow)
You can use pip install [filename].whl which file download from sse2 folder instead of using official AVX binary.
Please verify whether the below command is working.
pip3 install --upgrade tensorflow
You can use the below link for reference of tensorflow-windows-wheel.
https://github.com/fo40225/tensorflow-windows-wheel
I have built tensorflow wheel without AVX.
https://github.com/fo40225/tensorflow-windows-wheel/tree/master/1.6.0/py36/CPU/sse2
I wish this .whl may help you.
You can install the wheel file with pip. First change the current directory to install location. Then,
pip install tensorflow-1.6.0-cp36-cp36m-win_amd64.whl
If its not working please try to resolve it by downgrading protobuf from 3.6.1 to 3.6.0:
pip install protobuf==3.6.0
Got it fixed post looking for similar answers in internet...I had to install the tensorflow version 1.5 and the tensorflow backend loaded seamlessly

Categories