17
votes

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"?

7
you can leave the previous PATH and add this one (without overwriting)? - Salvador Dali
@SalvadorDali but will that cause some problems if - for example - numpy is installed in both paths and I try to import numpy? - Arabasta
try it. Right now you can see that other approach definitely causes some problem. - Salvador Dali
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
[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: stackoverflow.com/questions/35953210/… - Victoria Stuart

7 Answers

36
votes

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

16
votes

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
2
votes

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

1
votes

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
1
votes

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

conda install -c conda-forge tensorflow

0
votes

I solved the problem using this:

conda create --name=tensorenv python=3.4
source activate tensorenv
0
votes

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