4

On Ubuntu 14.04, I have installed Anaconda, which I use as my main Python interpreter. I now want to install the TensorFlow library and use this via Anaconda. So, I downloaded the relevant foo.whl file from the TensorFlow website, and then ran pip install foo.whl. After this, I ran pip freeze, and it showed me tensorflow==0.7.1 indicating that it was installed successfully.

However, using the Anaconda interpreter, when I run a Python file which has import tensorflow, it tells me ImportError: No module named 'tensorflow'. Additionally, if I search my Anaconda directory, there is no reference to TensorFlow.

Now at first, I thought this was because pip install was using pip that comes with the native Ubuntu installation. However, I have the line export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH in my .bashrc file, and so this suggests it would use Anaconda's pip.

Any idea what's going on? Thanks!

Karnivaurus
  • 18,315
  • 44
  • 129
  • 209
  • Have you checked some of the answers given in similar questions? http://stackoverflow.com/questions/19029333/how-to-check-that-the-anaconda-package-was-properly-installed?rq=1 http://stackoverflow.com/questions/29508309/anaconda-could-not-find-my-already-installed-package?rq=1 – Gabriel Mar 21 '16 at 17:22
  • This one seems very relevant too: http://stackoverflow.com/questions/33646541/tensorflow-and-anaconda-on-ubuntu?rq=1 – Gabriel Mar 21 '16 at 17:22
  • Is your export statement the last item in your bashrc? What path do you get when you execute ``which pip`` or ``type pip``? – notorious.no Mar 21 '16 at 17:29
  • 1
    Did you try `conda install` -- `conda`'s documentation is http://conda.pydata.org/docs/using/index.html – scooter me fecit Mar 21 '16 at 17:30
  • If I run `type pip`, I get `pip is hashed to (usr/bin/pip)`, but if I run `which pip`, I get `/home/karnivaurus/Libraries/Anaconda/bin/pip`... – Karnivaurus Mar 21 '16 at 17:33

3 Answers3

4

You can try the similar answer here: https://stackoverflow.com/a/33698750/5573572

Pretty much do these steps:

1. Uninstall TensorFlow from pip:

pip uninstall tensorflow

Do the above to avoid conflicts.

2. Install Python 3 in a virtual environment (version 0.7.1 as of this writing):

conda create -n <environment_name> python==3.5.1

3. Activate your virtual environment (do this every time you want to use TensorFlow):

source activate <environment_name>

4. Install a Conda version of TensorFlow in that environment (version 0.7.1 as of this writing):

conda install -c https://conda.anaconda.org/jjhelmus tensorflow

Remember to change "environment_name" to whatever you want to name your environment. After these, you should hopefully be able to import tensorflow. If not, then anaconda might be having trouble installing TensorFlow's dependencies. I'll run this on my machine to check real quick :p. I have confirmed that this works.

A possible reason that your installation attempt was not working is because Ubuntu 14.04 has Python 2.7 installed, in which many system programs depend on for the time being. As an aside, the Ubuntu development team is working on porting all of those programs to use Python 3 instead: https://wiki.ubuntu.com/Python/Python35Transition

Update: added instructions to include creating a virtual environment. The virtual environment helps because it allows you to use the Python commands within the environment instead of any system Python commands. So, commands like "pip" and "python" will use the ones in the environment, which also contains the TensorFlow libraries. To get out of the environment, do:

source deactivate
Community
  • 1
  • 1
Ed Solis
  • 96
  • 1
  • 1
  • 8
  • Thanks. I tried your solution, but it gave me the following message: `/home/karnivaurus/Anaconda/bin/python3: bad interpreter: No such file or directory`.... – Karnivaurus Mar 21 '16 at 17:49
  • Ok @karnivaurus, I've changed my answer, and verified it in my machine that it works (Ubuntu 14.04) – Ed Solis Mar 21 '16 at 20:28
  • Hey, let me know if you insist not using virtual environments, and I will change my answer. As a developer, I use them all the time, and it is a good habit to get into if you use Python a lot. – Ed Solis Mar 21 '16 at 23:49
0

Try without sudo:

pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl

instead of

sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
krasin
  • 123
  • 1
  • 6
0

First uninstall all the dependencies of tensorflow using

pip uninstall tensorflow

Then install tensorflow package with conda run:

 conda install -c jjhelmus tensorflow=0.10.0rc0

If you want to install tensorflow package with pip run:

pip install -i https://pypi.anaconda.org/jjhelmus/simple tensorflow

Sources: https://anaconda.org/jjhelmus/tensorflow

Abhishek Kumar
  • 181
  • 2
  • 6