Skip to content

Error importing tensorflow. Unless you are using bazel, you should not try to import tensorflow from its source directory #1402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ushnish opened this issue Mar 6, 2016 · 57 comments
Assignees

Comments

@ushnish
Copy link

ushnish commented Mar 6, 2016

These are the sequence of steps i followed to install the distributed version of TF

git clone --recurse-submodules https://github.com/tensorflow/tensorflow
./configure (default with GPU)
bazel build -c opt --config=cuda //tensorflow/cc:tutorials_example_trainer
bazel-bin/tensorflow/cc/tutorials_example_trainer --use_gpu (at this point saw the expected output and GPU being used)
bazel build -c opt --config=cuda --define=use_fast_cpp_protos=true //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.7.1-py2-none-any.whl
Processing /tmp/tensorflow_pkg/tensorflow-0.7.1-py2-none-any.whl
Installing collected packages: tensorflow
pip show tensorflow
Metadata-Version: 2.0
Name: tensorflow
Version: 0.7.1
Summary: TensorFlow helps the tensors flow
Home-page: http://tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: six, protobuf, wheel, numpy
Classifiers:
Development Status :: 4 - Beta
Intended Audience :: Developers
Intended Audience :: Education
Intended Audience :: Science/Research
License :: OSI Approved :: Apache Software License
Programming Language :: Python :: 2.7
Topic :: Scientific/Engineering :: Mathematics
Topic :: Software Development :: Libraries :: Python Modules
Topic :: Software Development :: Libraries
Entry-points:
[console_scripts]
tensorboard = tensorflow.tensorboard.tensorboard:main

Now for the error

python
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/tensorflow/init.py", line 23, in
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/init.py", line 41, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/init.py", line 35, in
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in
from google.protobuf import descriptor as _descriptor
ImportError: No module named protobuf

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

Can someone help me understand what might cause this? Thank you.

@shiyemin
Copy link

shiyemin commented Mar 6, 2016

You should start your python outside tensorflow directory. Because python will import tensorflow from current directory.

@raingo
Copy link
Contributor

raingo commented Mar 6, 2016

I had the same errors as you did. I solved this by reinstall protobuf, by pip install -U protobuf==3.0.0b2

@ushnish
Copy link
Author

ushnish commented Mar 6, 2016

@shiyemin yes of course I started the interpreter outside the tensorflow directory

@raingo I tried that but in python interpreter I still get same error. Do you have to do a bazel build for tensorflow by pass in this protobuf library into the build command?

@raingo
Copy link
Contributor

raingo commented Mar 6, 2016

Yes. I built from source, but I didn't do anything special for bazel. I
needed to upgrade protobuf manually because I install the wheel by

pip install wheel --no-deps -U

Sent from a mobile device
On Mar 6, 2016 3:45 PM, "ushnish" notifications@github.com wrote:

@shiyemin https://github.com/shiyemin yes of course I started the
interpreter outside the tensorflow directory

@raingo https://github.com/raingo I tried that but in python
interpreter I still get same error. Do you have to do a bazel build for
tensorflow by pass in this protobuf library into the build command?


Reply to this email directly or view it on GitHub
#1402 (comment)
.

@ushnish
Copy link
Author

ushnish commented Mar 6, 2016

@raingo did you do git clone --recurse-submodules https://github.com/tensorflow/tensorflow or clone without the submodules since you are installing protobuf separately

@ghost
Copy link

ghost commented Mar 7, 2016

Uninstall protobuf before building (or dl whl), everything works fine after that. Had the same issue.

sudo pip uninstall protobuf

@ushnish
Copy link
Author

ushnish commented Mar 7, 2016

@Dringite do you mean uninstall protobuf, build from the .whl and then install protobuf the way @raingo mentioned?

@ushnish
Copy link
Author

ushnish commented Mar 7, 2016

Problem solved @Dringite you were right, there was no need to have protobuf installed at all. The steps are

git clone --recurse-submodules https://github.com/tensorflow/tensorflow
sudo pip uninstall protobuf
cd tensorflow/
./configure
bazel build -c opt --config=cuda --define=use_fast_cpp_protos=true //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tenso
rflow_pkg
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.7.1-py2-none-any.whl

Notice that i added --define=use_fast_cpp_protos=true in the build command so it might have actually helped.

@Channndiii
Copy link

@ushnish I have followed your way to install tensorflow-0.7.1. In the future if I want to upgrade the version of tensorflow, is it necessary for me to follow your way to install new version? Or is there any other convenient ways?

@hhchen1105
Copy link

Tensorflow 0.9.0 also suffers from the same issue. The answer from @Dringite can solve the issue. (i.e., pip uninstall protobuf and tensorflow, then pip install tensorflow)

@ethanator
Copy link

ethanator commented Sep 23, 2016

Tensorflow 0.10.0 also suffers from the same issue. The answer from @raingo can solve the issue. (i.e. pip uninstall protobuf, then pip install wheel --no-deps -U)

@984958198
Copy link

According to the above method Still not solve
ubuntu 64
tensorflow-0.12.0rc0-cp27-cp27mu-manylinux1_x86_64.whl

`Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in
File "/root/tg2env/local/lib/python2.7/site-packages/tensorflow/init.py", line 24, in
from tensorflow.python import *
File "/root/tg2env/local/lib/python2.7/site-packages/tensorflow/python/init.py", line 60, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/root/tg2env/local/lib/python2.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/root/tg2env/local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in
_pywrap_tensorflow = swig_import_helper()
File "/root/tg2env/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: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.16' not found (required by /root/tg2env/local/lib/python2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so)

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
`

@baregawi
Copy link

baregawi commented Dec 5, 2016

I'm running Ubuntu 14.04.5 LTS with python==2.7, tensorflow==0.12.0rc0 (most recent in PyPy) and keras==1.1.0.

A quick hack to get you by:

sudo vim /usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py

and replace from tensorflow.python import pywrap_tensorflow with import pywrap_tensorflow around line 49 in the try portion of the try/catch.

@NewRem
Copy link

NewRem commented Dec 6, 2016

I got a similar error. It was solved when I run python from the parent directory of tensorflow. But I'm curious if I can import tensorflow from another directory? Because when I do, it shows this error.
"Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there."

@martinwicke
Copy link
Member

@baregawi Is this a new behavior in 0.12?

@NewRem how did you install TensorFlow?

@yifeif It obviously looks fine in our CI, any idea?

@martinwicke martinwicke reopened this Dec 6, 2016
@yifeif
Copy link
Contributor

yifeif commented Dec 6, 2016

Looks like it is related to this line when running tensorflow from source dir, https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/__init__.py#L49

This should be resolved by not running from the source dir.
@NewRem also curious how you installed tensorflow. You should be able to import tensorflow from a non-repo-source directory.

@984958198
Copy link

Thank you all, I solved the problem by upgrading the ubuntu

@NewRem
Copy link

NewRem commented Dec 6, 2016

@martinwicke @yifeif I used pip installation. To be exact, I used these three commands:

$ sudo easy_install pip
$ sudo easy_install --upgrade six

#the CPU version of the binaries to Pypi
$ sudo pip install --ignore-installed tensorflow

@baregawi
Copy link

baregawi commented Dec 6, 2016

@martinwicke I just pip install -U tensorflow after not having updated since September. But I remember having to do a similar hack in September: #4616

@martinwicke
Copy link
Member

@baregawi #4616 is different, we are removing spurious symbols from our packages, so a lot of these direct imports will stop working.

This issue is different, and in the past, this has pointed to tensorflow now being properly installed. It's hard to debug remotely though. @ushnish how many pythons do you have installed and which one is tensorflow installed in?

Can you install tensorflow in a virtualenv? If that works, then there's some problem with conflicting versions, either python/ipython or more than one tensorflow installation.

@R0rs12ach
Copy link

@martinwicke I installed tensorflow_gpu-0.12rc1-py2-none-any.whl step by step via the instruction of official site.

execute this command: sudo pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc1-py2-none-any.whl

Collecting tensorflow-gpu==0.12.0rc1 from https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc1-py2-none-any.whl
  Downloading https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow_gpu-0.12.0rc1-py2-none-any.whl (83.6MB)
    100% |████████████████████████████████| 83.6MB 7.5kB/s
Collecting mock>=2.0.0 (from tensorflow-gpu==0.12.0rc1)
  Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 33kB/s
Collecting numpy>=1.11.0 (from tensorflow-gpu==0.12.0rc1)
  Downloading numpy-1.11.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB)
    100% |████████████████████████████████| 3.9MB 16kB/s
Collecting protobuf==3.1.0 (from tensorflow-gpu==0.12.0rc1)
  Downloading protobuf-3.1.0-py2.py3-none-any.whl (339kB)
    100% |████████████████████████████████| 348kB 16kB/s
Collecting wheel (from tensorflow-gpu==0.12.0rc1)
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 19kB/s
Collecting six>=1.10.0 (from tensorflow-gpu==0.12.0rc1)
  Downloading six-1.10.0-py2.py3-none-any.whl
Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow-gpu==0.12.0rc1)
  Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow-gpu==0.12.0rc1)
  Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB)
    100% |████████████████████████████████| 102kB 28kB/s
Collecting setuptools (from protobuf==3.1.0->tensorflow-gpu==0.12.0rc1)
  Downloading setuptools-32.0.0-py2.py3-none-any.whl (477kB)
    100% |████████████████████████████████| 481kB 30kB/s
Installing collected packages: six, funcsigs, pbr, mock, numpy, setuptools, protobuf, wheel, tensorflow-gpu
Successfully installed funcsigs-1.0.2 mock-2.0.0 numpy-1.11.2 pbr-1.10.0 protobuf-3.1.0 setuptools-32.0.0 six-1.10.0 tensorflow-gpu-0.12.0rc1 wheel-0.29.0

But unfortunately, I got the same error as following output:

>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 60, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/tensorflow/python/__init__.py", line 49, in <module>
    from tensorflow.python import pywrap_tensorflow
  File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in <module>
    _pywrap_tensorflow = swig_import_helper()
  File "/Library/Python/2.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(/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so, 10): no suitable image found.  Did find:
	/Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: mach-o, but wrong architecture


Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.
>>> exit()

The version of mac system: OS X EI Captain
And I had try each ways above this issues list, but nothing change.

Thank u 4 any response.

@martinwicke
Copy link
Member

@R0rs12ach:
The hint is in this line:
Did find: /Library/Python/2.7/site-packages/tensorflow/python/_pywrap_tensorflow.so: mach-o, but wrong architecture

Are you installing this on PPC? If so, you'll have to install from source, our binary packages only support x86_64.

@MeilingShi
Copy link

@R0rs12ach: i had the same problem using mac OS X Yosemite.
i have tried everything written here but it didn't help.
At last i went back to the homepage of tensor flow and tried other installation methods. After that i have followed 'Anaconda installation' -> 'Using conda' i finally could run it properly. Not sure which action i have taken helped.

So far i have tried:

$ sudo easy_install pip
$ sudo easy_install --upgrade six

$ sudo pip install --upgrade $TF_BINARY_URL
pip uninstall protobuf
pip install wheel --no-deps -U)

git clone --recurse-submodules https://github.com/tensorflow/tensorflow
sudo pip uninstall protobuf
cd tensorflow/
./configure
bazel build -c opt --config=cuda --define=use_fast_cpp_protos=true //tensorflow/tools/pip_package:build_pip_package
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tenso
rflow_pkg
sudo pip install /tmp/tensorflow_pkg/tensorflow-0.7.1-py2-none-any.whl

and as said, instead of install with pip i have made it with Anaconda installation from trensorflow homepage: https://www.tensorflow.org/get_started/os_setup#anaconda_installation

Hope it will help you.

@R0rs12ach
Copy link

@martinwicke I think my computer's arch is :

Darwin MacBook-Pro.local 15.6.0 Darwin Kernel Version 15.6.0: Thu Jun 23 18:25:34 PDT 2016; root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

the fact is that my computer just x86_64

@MeilingShi : Thank u 4 ur advice, I will try it and paste the result

@R0rs12ach
Copy link

@MeilingShi I have tried what you said above, but nothing change. In fact, the cuda sdk do not support intel graphic 4000. So, i give up to install tensorflow_gpu_version on my mac which bought at 2013.

@martinwicke
Copy link
Member

@R0rs12ach yes, CUDA only works with NVIDIA graphics cards.

It's still confusing me that it would complain about the library architecture.

Others, I would like to understand this issue, but this thread has become too noisy. Whoever still has this problem, can you open a new issue with your system config according to the template?

@martinwicke
Copy link
Member

@rodrigomfw can you paste the error before that message? For some people on this thread it's that they have very old systems (CentOS 6.x) which don't support the pre-built binaries. For you it's probably something else since it only affects GPU.

@vrv, I think we should rephrase this error. Most of the time (100% of the time in this thread), this is a failure to import unrelated to the working directory.

@vrv
Copy link

vrv commented Jan 6, 2017

Yup, something changed and we now raise ImportError much more often, so the error message is unhelpful.

@MumMumMum
Copy link

I just uninstalled tensorflow and tensorflow-gpu both and then I just installed tensorflow-gpu... works perfectly fine for me

@shashankjariwala
Copy link

Facing this error when installing tensorflow on windows 8 with python 3.5 and importing it from IDLE. I think it is the same issue.

import tensorflow
Traceback (most recent call last):
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\python_35_2_64\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, 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:\python_35_2_64\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\python_35_2_64\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import tensorflow
File "C:\python_35_2_64\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import *
File "C:\python_35_2_64\lib\site-packages\tensorflow\python_init_.py", line 60, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\python_35_2_64\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, 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:\python_35_2_64\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\python_35_2_64\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\python_35_2_64\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

@yemengsky
Copy link

@gistya
Copy link

gistya commented Jan 17, 2017

I did everything above but I always get this:

Using TensorFlow backend.
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "run.py", line 1, in
import lstm
File "/Users/me/Documents/dev/LSTM/lstm.py", line 5, in
from keras.layers.core import Dense, Activation, Dropout
File "/Library/Python/2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/init.py", line 2, in
from . import backend
File "/Library/Python/2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/backend/init.py", line 67, in
from .tensorflow_backend import *
File "/Library/Python/2.7/site-packages/Keras-1.2.0-py2.7.egg/keras/backend/tensorflow_backend.py", line 1, in
import tensorflow as tf
File "/Library/Python/2.7/site-packages/tensorflow/init.py", line 24, in
from tensorflow.python import *
File "/Library/Python/2.7/site-packages/tensorflow/python/init.py", line 60, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tensorflow/python/init.py", line 49, in
from tensorflow.python import pywrap_tensorflow
File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in
_pywrap_tensorflow = swig_import_helper()
File "/Library/Python/2.7/site-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

@yemengsky
Copy link

@atabakd
Copy link

atabakd commented Jan 17, 2017

I got over the problem by reinstalling cuda 8.0 and cudnn 5.1

@luckyuho
Copy link

Maybe this can help you when you got this "Error importing tensorflow. Unless you are using bazel, you should not try to import tensorflow from its source directory" #559

@clarklight
Copy link

clarklight commented Jan 31, 2017

I am also facing the same issues, wondered if anyone has resolved it? But my error is slightly different ImportError: numpy.core.multiarray failed to import
I initially when installing with pip it had the error and i had to add --ignore-installed six to make the installation work, really not sure if that would affect anything.

But i have tried all the solutions mentioned above, and still facing that problem "Error importing tensorflow."

@luckyuho
Copy link

luckyuho commented Feb 1, 2017

try this one
#559
from author se7en007 commented on 4 Jan 2016
import numpy as np
np.path
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy']
exit()
sudo rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
...

@clarklight
Copy link

If anyone had the same problem as mine, i managed to fix it. My error was
ImportError: numpy.core.multiarray failed to import
Error importing tensorflow. Unless yo......

Because i am running on a Mac, there are 2 sets of numpy thats running at the same time, as the Mac came with Python installed, so even if you are updating the numpy, it wasnt updating the one thats needed for Tensorflow. I believe i ran sudo pip install numpy -U --upgrade or something like that so all versions of numpy would be upgraded within my Mac. Then it worked after that.

@brando90
Copy link

What does it mean to be in the "source directory". I am also having the same issue however, I have no idea what the source directory is.

@jhli973
Copy link

jhli973 commented Mar 3, 2017

seems no solution yet. I am installing gpu version on windows 10. The installation seems ok at least no error or warning.

pip install --ignore-installed --upgrade C:\Users\dbsnail\Downloads\tensorflow_gpu-1.0.0rc2-cp35-cp35m-win_amd64.whl

import tensorflow
Traceback (most recent call last):
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Anaconda2\envs\py35\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, in _call_with_frames_removed
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 "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python_init_.py", line 66, in
from tensorflow.python import pywrap_tensorflow
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\Anaconda2\envs\py35\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import *
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python_init_.py", line 72, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Anaconda2\envs\py35\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, in _call_with_frames_removed
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 "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python_init_.py", line 66, in
from tensorflow.python import pywrap_tensorflow
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Anaconda2\envs\py35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\Anaconda2\envs\py35\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

Failed to load the native TensorFlow runtime.

@jhli973
Copy link

jhli973 commented Mar 3, 2017

I got the solution, install cuDNN v5.1 for CUDA 8.0
You need to register a NVIDIA accelerated computing developer program, then from here (https://developer.nvidia.com/rdp/cudnn-download) download and unzip it.
Copy all three subfolders and past it under CUDA folder, in my case is
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA

Then , you should be able to load tensorflow without any error

NOTE, I use python 3.5

@mzmmoazam
Copy link

I first installed wheel, then the tensorflow was installed on my machine(using windows 10).

Now, it is not getting imported here is the error :

Using TensorFlow backend.
Traceback (most recent call last):
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)])
File "C:\Users\mzm\Anaconda3\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 29, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in swig_import_helper
import _pywrap_tensorflow
ModuleNotFoundError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/mzm/PycharmProjects/mzm/FAQ bot/rough.py", line 36, in
from keras.models import Sequential, Model
File "C:\Users\mzm\Anaconda3\lib\site-packages\keras_init_.py", line 3, in
from . import activations
File "C:\Users\mzm\Anaconda3\lib\site-packages\keras\activations.py", line 4, in
from . import backend as K
File "C:\Users\mzm\Anaconda3\lib\site-packages\keras\backend_init_.py", line 73, in
from .tensorflow_backend import *
File "C:\Users\mzm\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in
import tensorflow as tf
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import *
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python_init_.py", line 60, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)])
File "C:\Users\mzm\Anaconda3\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 29, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\mzm\Anaconda3\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in swig_import_helper
import _pywrap_tensorflow
ModuleNotFoundError: No module named '_pywrap_tensorflow'

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

Does any know how to fix it??

@ShashwatHiregoudar
Copy link

ShashwatHiregoudar commented Aug 19, 2017

Guys its simple,
Come out of the tensorflow environment
like -
source deactivate tensorflow
then try your tensor board
Ex: tensorboard --logdir=/tmp/tboard/output
Worked for me : )

@yick2232
Copy link

@Shiv751
Copy link

Shiv751 commented Sep 10, 2017

I am new to TensorFlow and I am facing the same issue. Kindly suggest me to get started with this journey as soon as possible.

Traceback (most recent call last):
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, in _call_with_frames_removed
ImportError: DLL load failed: %1 is not a valid Win32 application.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\WorkspaceMaven\A-python\Test.py", line 1, in
import tensorflow as tf
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow_init_.py", line 24, in
from tensorflow.python import *
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python_init_.py", line 60, in
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\importlib_init_.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 666, in _load_unlocked
File "", line 577, in module_from_spec
File "", line 906, in create_module
File "", line 222, in _call_with_frames_removed
ImportError: DLL load failed: %1 is not a valid Win32 application.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python_init_.py", line 54, in
from tensorflow.python import pywrap_tensorflow
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('pywrap_tensorflow')
File "C:\Users\SEM\AppData\Local\Programs\Python\Python35\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'

Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

@newton3
Copy link

newton3 commented Sep 12, 2017

Hi, I got the same issue:

Error importing tensorflow.  Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter
from there.

I do not know where or what is tensorflow source tree, or where is tensorflow source directory. I just followed the instructions here - https://www.tensorflow.org/install/install_windows and now trying to follow this - https://www.tensorflow.org/get_started/get_started

This was exactly after following the getting started guide and trying a import tensorflow as tf.
Wondering why is this issue closed when so many people are still facing the same.
I couldn't find the solution anywhere on this thread or on stackoverflow.

Please help!!

@Shiv751
Copy link

Shiv751 commented Sep 12, 2017 via email

@Periter
Copy link

Periter commented Oct 20, 2018

Oh,my solution is upgrading the pip to latest version, then use it to reinstall tensorflow

@cyberking18
Copy link

lol, you guys are just naive! It's clearly written that you cant import tensorflow on the terminal itself, C'mon go and create a python file and then compile it silly!

@LucianaMarques
Copy link

This thread seems somewhat old, but just to share the problem I had and how I solved it.

I first tried to import keras, but I faced the same error on this issue title.

I uninstalled protobuf and updated tensorflow. It worked.

$ pip uninstall protobuf
$ pip install -U tensorflow

@Anu-1-sha
Copy link

1.Download Python 3.5.2 (3.5.2 only!!)
2.In command prompt : pip install tensorflow
(ignore this --Cache entry deserialization failed, entry ignored)
3.:python
4.>>import tensorflow as tf (
if no error then successfully installed
5.>>print(tf.version)
(use double underscore above)
Screenshot (205)
)

fsx950223 pushed a commit to fsx950223/tensorflow that referenced this issue Nov 28, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…gfx90a

Permanently enabling sramecc for gfx90a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests