17

On my Ubuntu 14.04, I have installed tensorflow, using "pip", as specified in the Tensorflow Installation instructions and I made sure it was working by importing it in python and it did work.

Then, I installed Anaconda and it changed my .bashrc file by adding the following line to it:

export PATH="/home/sonny/anaconda2/bin:$PATH"

But because of this change, now it looks into the PATH above, which doesn't contain tensorflow. now I can't import tensorflow in my python code.

What is the proper way to extend the $PATH environment variable so that it stays using everything from anaconda2 but it becomes able to import "tensorflow"?

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
Arabasta
  • 805
  • 2
  • 7
  • 13
  • you can leave the previous PATH and add this one (without overwriting)? – Salvador Dali Nov 11 '15 at 08:16
  • @SalvadorDali but will that cause some problems if - for example - numpy is installed in both paths and I try to import numpy? – Arabasta Nov 11 '15 at 14:45
  • try it. Right now you can see that other approach definitely causes some problem. – Salvador Dali Nov 11 '15 at 19:48
  • youre confused about the PATH env variable and how python imports modules. When you run python, your terminal looks for the python executable on the PATH, which will be in the anaconda folder. When you import, *python* does not refer to PATH, but looks (eventually) in an inplementation dependant default. This is different for anaconda python than the system python, hence it can't find modules you installed before anaconda (unless anaconda has them also). – drevicko Jan 11 '16 at 21:54
  • [Not sure whether to post this as a comment or an answer; opting for the former, so as to not double-post.] I was also having issues importing TensorFlow (complied from source), installed in a venv. I posted a facile (non-PIP) summary, here in a related thread: http://stackoverflow.com/questions/35953210/error-running-basic-tensorflow-example/38536906#38536906 – Victoria Stuart Jul 23 '16 at 00:19

7 Answers7

36

I solved the problem but in a different way! I found a link where the tensorflow.whl files were converted to conda packages, so I went ahead and installed it using the command:

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

and it worked, since the $PATH points to anaconda packages, I can import it now!

Source is here

Arabasta
  • 805
  • 2
  • 7
  • 13
16

Since v0.10.0, tensorflow is a community maintained conda package in the conda-forge channel. Hence, it can be installed directly with the following command:

conda install -c conda-forge tensorflow

The instructions on the TensorFlow documentation has also been updated.

To facilitate future updates, it is probably a good idea to add conda-forge channel into your conda config:

conda config --add channels conda-forge

In fact, tensorflow=0.10.0rc0 was recently added onto the Anaconda default channel and will be installed instead if the conda-forge channel is not specified:

conda install tensorflow
yxtay
  • 506
  • 4
  • 11
  • Bump. This worked for me (Ubuntu 14.04, latest Anaconda for Python 2.7), but the accepted answer is getting old and did not work. – john_science Oct 29 '16 at 20:36
  • This worked for me on macOS 10.12, Anaconda for Python 2.7 – Karthik Kannan Jan 04 '17 at 17:59
  • Unfortunately this only seems to have the CPU version, not the GPU. – ComputerScientist Jan 12 '17 at 15:53
  • I used anaconda channel to install tensorflow-gpu, but I see a lot of "The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations." warnings. Is there a way to check if conda-forge version of tf compiled any differently from the one in anaconda? – Prakhar Agrawal Apr 05 '18 at 11:09
2

I had the same problem and decided it was easiest to start over, install Anaconda first and then TensorFlow after that.

gauss256
  • 2,603
  • 4
  • 23
  • 23
  • But how would that solve the problem? Tensorflow does not add any path to the bashrc file so it will still point to anaconda – Arabasta Nov 11 '15 at 14:48
  • 1
    When you pip-install TensorFlow it goes into the site packages for whatever Python is current. If you install Anaconda afterward, the location of the Python distribution changes and it won't know anything about where you installed TensorFlow previously. If you do it in the other order, then TensorFlow becomes a site package for the Anaconda distribution. It doesn't have much to do with $PATH. My understanding of this may not be perfect, but it worked for me! – gauss256 Nov 11 '15 at 19:10
  • i have just tried your suggestion. It did not work for me. It seems that I would need to make the path environment variable point to the tensorflow library while still pointing at the anaconda package – Arabasta Nov 11 '15 at 19:21
  • as gauss256 suggests, you shouldn't need to touch the PATH (nor the PYTHONPATH, which is where python looks when importing modules). If you pip-install TensorFlow once anaconda is installed (and added to you PATH), it should work. If not, you're terminal session has something muddled - relaunch your terminal, check you bashrc, reinstall, reset, ... – drevicko Jan 11 '16 at 21:36
  • 1
    actually, you can pip install it again after anaconda is installed, and you'll have it in both places (in anaconda's python folders and in the system python folders). Perhaps the best way to go. – drevicko Jan 11 '16 at 21:38
1

I suspect that pip is giving you a TensorFlow installation in cpython, not anaconda.

How about a virtualenv?

# Create env
$ virtualenv --python=/path/to/anaconda /path/to/your/env

# Activate env
$ source /path/to/your/env/bin/activate

# Install Tensorflow
$ pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.5.0-cp27-none-linux_x86_64.whl
Freek Wiekmeijer
  • 4,556
  • 30
  • 37
1

Install tensorflow from the following command. Conda will take care of the installation process.

conda install -c conda-forge tensorflow

Sai Harsha
  • 39
  • 4
0

I solved the problem using this:

conda create --name=tensorenv python=3.4
source activate tensorenv
gkhnavarro
  • 446
  • 2
  • 14
0

Actually, the TensorFlow Official website made every detail of installing. The Operation System Windows, Mac OS, Ubuntu; the environment with GPU or just CPU, every single detail of problems you may come up with.

Check this out

Installing TensorFlow on Ubuntu with Anaconda

you will not regret.

Once you visit that you may also find like

Installing TensorFlow on Windows with Anaconda

Fuevo
  • 132
  • 1
  • 10