67

I have just reinstalled latest tensorflow on ubuntu:

$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
[sudo] password for ubuntu: 
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
 Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl (13.8MB)
 100% |████████████████████████████████| 13.8MB 32kB/s 
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: protobuf==3.0.0b2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: tensorflow
 Found existing installation: tensorflow 0.7.1
 Uninstalling tensorflow-0.7.1:
 Successfully uninstalled tensorflow-0.7.1
Successfully installed tensorflow-0.7.1

When following the directions to test it fails with cannot import name pywrap_tensorflow:

$ ipython
/git/tensorflow/tensorflow/__init__.py in <module>()
 21 from __future__ import print_function
 22 
---> 23 from tensorflow.python import *
/git/tensorflow/tensorflow/python/__init__.py in <module>()
 43 _default_dlopen_flags = sys.getdlopenflags()
 44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
 46 sys.setdlopenflags(_default_dlopen_flags)
 47 
ImportError: cannot import name pywrap_tensorflow

Is there an additional change needed to my python or ubuntu/bash environment?

Infinite Loops
6813 gold badges11 silver badges24 bronze badges
asked Mar 12, 2016 at 2:55

11 Answers 11

173

From the path in your stack trace (/git/tensorflow/tensorflow/...), it looks like your Python path may be loading the tensorflow libraries from the source directory, rather than the version that you have installed. As a result, it is unable to find the (compiled) pywrap_tensorflow library, which is installed in a different directory.

A common solution is to cd out of the /git/tensorflow directory before starting python or ipython.

answered Mar 12, 2016 at 21:22
Sign up to request clarification or add additional context in comments.

3 Comments

Apologies for the delay. It seems you were correct: I just started ipython from my home dir and it works fine import tensorflow as tf
This doesn't work for me. I can see C:\Python35\Lib\site-packages\tensorflow\python_pywrap_tensorflow_internal.pyd but get the error: from tensorflow.python.pywrap_tensorflow_internal import * ImportError: DLL load failed: The specified module could not be found.
I am still scratching my head at this solution. It works, but a python package should never depend on the current working directory to load a dependency. As a result, I can't seem to configure my IDE (pydev) to use tensorflow-gpu. tensorflow (cpu) worked fine. Am I missing something?
14

The command below helped me.

 pip install tensorflow --upgrade --force-reinstall
answered Feb 21, 2018 at 0:49

Comments

4

I compiled, installed TensorFlow from source (GitHub: https://github.com/tensorflow/tensorflow) in a Python 2.7 virtual environment (venv). It worked fine, but I needed (as others have mentioned, e.g. user "mrry" at Error running basic tensorflow example) to cd out of the partition in which I had compiled TensorFlow, to another partition, in order to be able to import tensorflow into Python. Otherwise, I got various errors, depending on which (source partition) directory I was in. To clarify:

 source: /mnt/Vancouver/apps/tensorflow
can't import tf: Python launched in any of /mnt/...
 can import tf: Python launched in /home/victoria/...

I later just followed the instructions here,

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation

and everything just works, fine.

For reference, I am operating on

  • Arch Linux [4.6.3-1-ARCH] x86_64
  • Intel i7-4790
  • xfce 4.12 desktop environment

INSTALL STEPS:

Modify paths, venv names as per your preferences.

  1. Create tf-env:

    cd /home/victoria/anaconda3/envs
    conda create -n tf-env python=2.7 anaconda
    

Note: appending the 'anaconda' metapackage installs ALL Anaconda packages (NumPy; ...).

  1. Source activate that venv (tf-env)

    source activate tf-env
    

Note: added to ~/.bashrc as an alias:

alias tf='echo " [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env'
  1. Install TensorFlow in the tf-env venv:

    (tf-env)$ conda install -c conda-forge tensorflow
    

THIS obviates the use of pip (including the *.whl install script), an alternative approach to installing TensorFlow that is described here:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md).

WORKS!

(tf-env)[victoria@victoria ~]$ P
 [P: python]
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow
>>> print tensorflow.__version__
0.9.0
>>> [Ctrl-D]
(tf-env)[victoria@victoria ~]$

You may then work with TensorFlow in the tf-env; e.g., in Jupyter notebooks launched in this (tf-env) venv.

answered Jul 23, 2016 at 0:16

Comments

2

Tensorflow 2.0 Compatible Answer: Both mrry's solution and neustart47's work for Tensorflow Version>= 2.0.

Answer 1: cd out of the /git/tensorflow directory before starting python or ipython.

Answer 2: pip install tensorflow --upgrade --force-reinstall or
!pip install tensorflow==2.0 --force-reinstall

answered Feb 12, 2020 at 9:55

Comments

1

In my python -m venv environment it appeared to be fixed by:

pip uninstall tensorflow

Change requirements.txt to say tensorflow==1.5.0 instead of tensorflow==1.8.0.

pip install -r requirements.txt
answered Jun 20, 2018 at 2:13

Comments

1

if you using CPU manufactured before 2011 then downgraded the tensorflow version from 1.8.0 to 1.5.0 or 1.2.0 and try to import the module it worked for me.

answered Jul 10, 2018 at 7:46

Comments

0

Installing via the following command solves the problem:

pip install --upgrade

Here's the link to download

answered Aug 17, 2018 at 23:04

Comments

0

I figured out that TensorFlow 1.12.0 only works with Python version 3.5.2. I had Python 3.7 but that didn't work. So, I had to downgrade Python and then I could install TensorFlow it works.

To downgrade your python version from 3.7 to 3.6

conda install python=3.6.8
answered Jan 23, 2019 at 2:39

Comments

0

I'm using tensorflow 1.13.1. Just reinstalling tensorflow worked for me.

answered Jun 1, 2019 at 22:31

Comments

0

I also have this issue and have been looking into it for a long time. It seems that there is no such problem on python 3+. On py2.7- The problem is actually on google.protobuf

Solution 1:

pip uninstall protobuf
pip uninstall google
pip install google
pip install protobuf
pip install google-cloud

Solution 2:

create an __init__.py in "google" folder.

cd /path/to/your/env/lib/python2.7/site-packages/google
touch __init__.py

Hopefully it will work.

answered Jul 17, 2019 at 5:10

Comments

-7

I resolve the problem. Try the follow command:

pip install --upgrade pip

m_callens
6,4029 gold badges35 silver badges59 bronze badges
answered Jul 7, 2016 at 19:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.