Error when importing TensorFlow in Python on Windows - python

I am running Python 2.7.10 and I successfully installed TensorFlow, using pip install
https://storage.googleapis.com/tensorflow/mac/tensorflow-0.5.0-py2-none-any.whl.
When I run the python interpreter and attempt to import the tensorflow module, I get the following error:
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\__init__.py", line 4, in <module>
from tensorflow.python import *
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\__init__.py", line 22, in <module>
from tensorflow.python.client.client_lib import *
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\client\client_lib.py", line 35, in <module>
from tensorflow.python.client.session import InteractiveSession
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\client\session.py", line 11, in <module>
from tensorflow.python import pywrap_tensorflow as tf_session
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\Or\AppData\Local\Enthought\Canopy\User\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
import _pywrap_tensorflow
ImportError: No module named _pywrap_tensorflow

you can use pip to install tensorflow
pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.0rc0-cp35-cp35m-win_amd64.whl
If you are trying to install on windows , you will have to have python3.5 x64 bit and along with that you need to install Visual C++ 2015 redistributable (x64 version) to be able to import tensorflow

Judging by the paths in the output, it looks like you are trying to run TensorFlow on Windows. The package that you have installed is a Mac OS X binary distribution of TensorFlow.
Unfortunately, Windows is not currently supported by TensorFlow, and it is unlikely to be supported before its build system (Bazel) adds Windows support. There is some discussion of progress towards a Windows version on this GitHub issue, and an unsupported contribution that builds TensorFlow using CMake on Windows.

Related

Faild to importing tensorflow [duplicate]

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.

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.

install and import tensorflow and keras

I am going mad for installing and import tensorflow for 6 weeks. I did everything; I installed it from spyder, Conda prompt and with different commands like pip install tensorflow and conda install tensorflow. my python version is 3.7 and after install when I want to import tensorflow in spyder I get this message:
import tensorflow
Traceback (most recent call last):
File "<ipython-input-4-d6579f534729>", line 1, in <module>
import tensorflow
File "C:\Users\sally\Anaconda3\lib\site-packages\tensorflow\__init__.py", line 27, in <module>
from tensorflow._api.v2 import audio
File "C:\Users\sally\Anaconda3\lib\site-packages\tensorflow\_api\v2\audio\__init__.py", line 8, in <module>
from tensorflow.python.ops.gen_audio_ops import decode_wav
File "C:\Users\sally\Anaconda3\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\Users\sally\Anaconda3\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 9, in <module>
from google.protobuf import symbol_database as _symbol_database
File "C:\Users\sally\Anaconda3\lib\site-packages\google\protobuf\symbol_database.py", line 184, in <module>
_DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: module 'google.protobuf.descriptor_pool' has no attribute 'Default
This is a very common issue. I have been there.
First: provide the following information:
- what operating system?
- do you want to run on cpu or gpu?
- if gpu, what gpu do you have?
- are your drivers up to date?
- Are your trying to run tensorflow though an IDE like Pycharm, is it more like Jupyter notebook stuff, or just cmd.
Second: There are some link that might be usefull. Here they are.
https://www.tensorflow.org/install/pip
https://www.tensorflow.org/install/gpu#software_requirements
There is a video that helped me, it might help you as well. With tensorflow it is really important to follow the instructions precisely, not missing any steps, and very important, not assuming that installing something with a higher version is no issue. If it says install 'whatever program'.version.1.1.x you can not install 'whatever program'.version.1.1.y
https://www.youtube.com/watch?v=qrkEYf-YDyI&t=1575s

Anaconda with Tensorflow: No module named any_pb2

I have just installed Anaconda in a Ubuntu 14.04. Then I installed tensorflow using
conda install -c https://conda.anaconda.org/jjhelmus tensorflow
Then I installed protobuf
conda install -c https://conda.anaconda.org/anaconda protobuf
However, I am not able to solve this issue:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/daniel/anaconda2/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/home/daniel/anaconda2/lib/python2.7/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 81, in execfile
builtins.execfile(filename, *where)
File "/home/daniel/Documents/Cursos/UnB/Metodos Computacionais/2016/Notas de Aula/Part II - Aula 1 Regression Linear Models/biasVersusVarianceSeveralData.py", line 8, in <module>
import tensorflow as tf
File "/home/daniel/anaconda2/lib/python2.7/site-packages/tensorflow/__init__.py", line 23, in <module>
from tensorflow.python import *
File "/home/daniel/anaconda2/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 69, in <module>
from tensorflow.python.training import training as train
File "/home/daniel/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/training.py", line 149, in <module>
from tensorflow.python.training.saver import generate_checkpoint_state_proto
File "/home/daniel/anaconda2/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 29, in <module>
from google.protobuf.any_pb2 import Any
ImportError: No module named any_pb2
Use the instructions on the TensorFlow site.
TLDR;
I am posting this as an answer because people don't look for answers in the comments.
Here's my comment on the issue from github, hope this helps.
"For anyone else who is running into the same issue, I was also having similar problems when trying to import tensorflow on notebook via jupyter. The modules were installed using conda. After spending two days on it without any success (kept getting the same, no module any_pb2/contrib), it was obvious it was a notebook problem and not tensorflow related since I could import tensorflow from python shell. So I decided to switch back to vanilla python and installed everything manually (tensorflow via pip & got rid of jupyter & installed ipython instead) and now I am able to import tensorflow from my ipython notebook."
Original comment link: https://github.com/tensorflow/tensorflow/issues/1161#issuecomment-188664103
The following worked for me:
conda install -c https://conda.anaconda.org/jjhelmus tensorflow

Python unable to import tensorflow to Mac OS X 10.8

I am trying to install tensorflow on my mac air (specs: OSX 10.8.4, 4GB RAM). While tensorflow installs cleanly, as on the tensorflow.org page, and I am able to do $ source bin/activate to get a tensorflow prompt, I am not able to import the package in python. This is what I get:
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/tensorflow/__init__.py", line 4, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/__init__.py", line 22, in <module>
from tensorflow.python.client.client_lib import *
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/client_lib.py", line 35, in <module>
from tensorflow.python.client.session import InteractiveSession
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 11, in <module>
from tensorflow.python import pywrap_tensorflow as tf_session
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
_pywrap_tensorflow = swig_import_helper()
File "/usr/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so, 2): Symbol not found: ___sincos_stret
Referenced from: /usr/local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so
Expected in: /usr/lib/libSystem.B.dylib
in /usr/local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so
I looked at the common problems section on tensorflow, as well as searched for the ImportError above but have had no luck so far. I wonder if this is a protobuf issue as referenced in Error in python after 'import tensorflow': TypeError: __init__() got an unexpected keyword argument 'syntax' .
Thanks in advance.
The issue appears to be that the binary distribution of TensorFlow is not compatible with Mac OS X 10.8. The relevant part of the error message is this one:
Symbol not found: ___sincos_stret
According to various sources, this is a known issue when using binaries compiled for a newer version of Mac OS X on 10.8 (Mavericks), because the symbol ___sincos_stret is not defined in the standard libraries for that version of the OS.
To address this, you will need to (i) upgrade to Mac OS X 10.9 or later, (ii) follow the instructions to install from source, or (iii) use Docker.
I had similar issue. I used docker toolbox and was able to run tensorflow. You can follow my question and my solution.

Categories

Resources