Faild to importing tensorflow [duplicate] - python

I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu

tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.

Related

Tensorflow installation on Windows: DLL load failed while importing _pywrap_tensorflow_internal

I ran through the TensorFlow object detection installation on Windows.
https://medium.com/riow/tensorflow-object-detection-on-windows-ad10bfde217c
After successfully installing TensorFlow object detection,
I ran following command to test, and receiving error below. How can this be fixed?
python object_detection/builders/model_builder_test.py
Error: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing pywrap_tensorflow_internal: The specified module could not be found.
Traceback (most recent call last):
File "object_detection/builders/model_builder_test.py", line 21, in
from object_detection.builders import model_builder
File "c:\testimage\models\research\object_detection\builders\model_builder.py", line 23, in
from object_detection.builders import anchor_generator_builder
File "c:\testimage\models\research\object_detection\builders\anchor_generator_builder.py", line 23, in
from object_detection.anchor_generators import flexible_grid_anchor_generator
File "c:\testimage\models\research\object_detection\anchor_generators\flexible_grid_anchor_generator.py", line 17, in
import tensorflow.compat.v1 as tf
File "C:\TestImage\models\venv\lib\site-packages\tensorflow_init.py", line 41, in
from tensorflow.python.tools import module_util as module_util
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python_init.py", line 40, in
from tensorflow.python.eager import context
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\eager\context.py", line 35, in
from tensorflow.python import pywrap_tfe
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in
from tensorflow.python import pywrap_tensorflow
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\TestImage\models\venv\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: The specified module could not be found.
Currently using Python 3.8 with latest tensorflow, with tensorflow-cpu
tldr;
You need to install the C++ redistributable mentioned on the install page before installing TensorFlow so that TensorFlow can use it to generate code at install time.
Details:
I'm not an expert but it sounds like this was key:
The pywrap_tensorflow_internal.py module you are missing appears to me to be a SWIG-generated python interface to a C++ library, or something of that nature. My guess is, that file gets generated when you install TensorFlow (it reminds me of how some Ruby gems have to compile C++ when you install them, for whatever that's worth). Since you don't have that generated file, my guess is that the C++ package mentioned on the TensorFlow install page is needed for that code generation, so you need to have the C++ package installed before installing TensorFlow.
Totally a guess, but perhaps you installed the C++ package after TF. In that case, you should be able to uninstall TF, install the C++ package, and then install TF again.
Maybe a lingering question is if there were any indicative error messages on installing TF about the missing C++ package and if not, maybe there should be.

Python: How do I resolve this ImportError?

I installed Tensorflow through pip install and it was successful but when i try to use it I have this ImportError:
Traceback (most recent call last):
File "C:\Users\AKIN\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: 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/AKIN/PythonProjects/sample_codes/trial_tf.py", line 2, in <module>
import tensorflow as tf
File "C:\Users\AKIN\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\AKIN\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\__init__.py", line 39, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow
File "C:\Users\AKIN\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\AKIN\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed while importing _pywrap_tensorflow_internal: A dynamic link library (DLL) initialization routine failed.
I have checked this and I have seen Windows build failing but I don't know if that's what affecting it:
https://github.com/tensorflow/tensorflow
What is going on?
After hundreds of Google searches and Youtube videos, I found the solution to this problem about a month ago. Unlike other third-party modules in python (e.g. Pandas, Matplotlib, etc.)- which require pip install - there are a different set of steps including installing NVIDIA with a Cuda-enabled GPU or CPU (Tensorflow works with either one) and activating a cond environment.
One youtube video I found to be particularly useful briefly explains each step to installing tensorflow without a DLL error. Here is the link: https://www.youtube.com/watch?v=5Ym-dOS9ssA&t=327s
The instructor uses Pycharm, but I am sure you can easily follow each step with another IDE.
If you have any questions or want clarification, please do not hesitate to ask. Best of luck! :)

i'm using python 3.7.7 but i have a problem while importing tensorflow

I'm new at python (version of python 3.7.7) and I'm trying to run a finished project, I imported everything but tensorflow is not working the error is shown down below:
Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import * 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/Desktop/adsp/train.py", line 1, in <module>
import tensorflow as tf File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py",
line 41, in <module>
from tensorflow.python.tools import module_util as _module_util File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\__init__.py",
line 39, in <module>
from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 83, in <module>
raise ImportError(msg) ImportError: Traceback (most recent call last): File
"C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import * 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.
The issue is of compatibility. The version of tensorflow which you are trying to run with python 3.7 is not compatible with the same. In order to check for possible compatible versions please visit this link.
Also in case you are facing too many issues while trying to install some library in python and your work is getting held, I'd recommend you to make use of Google Colab.
There you won't need to worry about installation of packages. Although one must experience the installation and setup of packages as a learning.
Try uninstalling tensorflow from pip and reinstalling it again. It seems you have an import error. Also if you have two or more Python versions on your machine, this can cause issues sometimes

Tensorflow Error: ImportError: DLL load failed: The specified module could not be found

I've looked through previous answers to similar questions but couldn't find the answer that worked for me.
I've worked with TensorFlow for a long time. Currently trying out Yolov4 which has a requirement to use Tensorflow version 2.3.0, so I decided to install that one.
Anaconda's latest release is 2.1.0 that works great on my computer. So since that was not enough, I created a new environment and installed Tensorflow with pip install tensorflow-gpu which installs version 2.3.0 seemingly without errors.
Then for the import tensorflow as tf I get this error. Any ideas what to try to resolve this?
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
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 "<stdin>", line 1, in <module>
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\__init__.py", line 41, in <module>
from tensorflow.python.tools import module_util as _module_util
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\__init__.py", line 40, in <module>
from tensorflow.python.eager import context
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\eager\context.py", line 35, in <module>
from tensorflow.python import pywrap_tfe
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\pywrap_tfe.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 83, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\mazat\Anaconda3\envs\tf23\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 64, in <module>
from tensorflow.python._pywrap_tensorflow_internal import *
ImportError: DLL load failed: The specified module could not be found.
Looks like the problem was the old version of Redistributable for Visual Studio.
With the new version from here, it seems to work thus far!
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
I had a similar problem and update Visual Studio (https://visualstudio.microsoft.com/pt-br/downloads/) worked for me.

TensorFlow fails to load runtime after installation from source

I started compiling TensorFlow from source on Ubuntu Linux 16.06 LTS, running the commands from the TensorFlow Linux compilation instructions.
My CUDA and CuDNN setup works, as the pre-compiled TensorFlow nvidia-docker image works.
After using bazel to build the TensorFlow Python wheel, and then installing the wheel with pip, I get the following error message when trying to import TensorFlow:
>>> import tensorflow
Traceback (most recent call last):
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/james/workspace/tensorflow/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/james/workspace/tensorflow/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/james/workspace/tensorflow/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
ImportError: No module named 'tensorflow.python.pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
This error happens when you are running Python from the TensorFlow source directory after having installed the Python wheel.
A similar error happens when you try importing TensorFlow before installing the Python wheel.
The solution to this problem is to change your working directory to something else, while still remaining in the virtualenv that you installed the Python wheel to.

Categories

Resources