5

I am using python3 and have installed tensorflow-gpu using:

pip3 install tensorflow-gpu==1.13.1

And have checked that it is installed by:

pip3 show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.13.1
Summary: TensorFlow is an open source machine learning framework for 
everyone.
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: opensource@google.com
License: Apache 2.0
Location: /usr/lib64/python3.6/site-packages
Requires: tensorflow-estimator, keras-applications, termcolor, absl-py, six, 
astor, protobuf, wheel, keras-preprocessing, gast, grpcio, numpy, 
tensorboard
Required-by:

but when I do the following it gives me an error:

user:/home/mydirectory # python3
Python 3.6.5 (default, Mar 31 2018, 19:45:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/tensorflow/__init__.py", line 24, 
in <module>
    from tensorflow.python import pywrap_tensorflow  # pylint: 
disable=unused-import
  File "/usr/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py", line 25, in <module>
    from tensorflow.python.platform import self_check
ModuleNotFoundError: No module named 'tensorflow.python.platform'

I see from the error that its looking for tensorflow in directory

/usr/lib/python3.6/site-packages/tensorflow

But pip indicates that its installed at

/usr/lib64/python3.6/site-packages

How can I fix this issue?

Harry Boy
  • 4,159
  • 17
  • 71
  • 122
  • Is the `#` in `user:/home/mydirectory #` mean root user in this case? If so, there might be different configurations for root compared to your user. – McAngus Jun 27 '19 at 15:30
  • Which OS are you using? Please specify the version also? – Tarun Lalwani Jun 27 '19 at 18:06
  • Can it be that your distro has removed the symlink `/{usr,}/lib -> /{usr,}/lib64` recently and the migration didn't go smoothly? `/lib` should be for 32bit stuff only. Can you also add the output of `python3.6 -m site` to the question? – hoefling Jun 27 '19 at 19:23
  • @Harry Boy please try to install with root or sudo. then try pip3 --version shekh@shekh:~$ pip3 --version pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5) shekh@shekh:~$ python3 Python 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> – Shekh Firoz Alam Jul 01 '19 at 10:16

4 Answers4

4
Please follow below steps..
0) please login with root permission or sudo and write this command in terminal 

1)pip3 install tensorflow-gpu==1.13.1   

2)pip3 --version
  pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)   
3)shekh@shekh:~$ python3
  Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
  [GCC 5.4.0 20160609] on linux
  Type "help", "copyright", "credits" or "license" for more information.
  >>>

https://www.tensorflow.org/install/pip

 for reference

tensorflow test run

Shekh Firoz Alam
  • 192
  • 3
  • 15
2

See https://github.com/tensorflow/tensorflow/issues/374

Are you opening the terminal from within the tensorflow directory?

"Actually I had this issue because I was trying to import tensorflow from a python session inside the tensorflow repo folder, going to some other folder and starting python and importing tensorflow worked for me."

Sohrab T
  • 625
  • 4
  • 14
0

I also had this error and it was solved with this command

python2:

PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/dist-packages/"
export PYTHONPATH

python3:

PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python3.6/dist-packages/"
export PYTHONPATH
Miladfa7
  • 102
  • 1
  • 7
0

I encountered a similar error on a Windows 10 system.

There, I had a second tensorflow install under AppData\Roaming\Python\.... This install was likely a product of some previous work that I did not clean up properly, so for me, removing the content of the site-packages directory solved the issue. After that I could import tensorflow without any problems.

André
  • 1,034
  • 9
  • 19