Karnivaurus Karnivaurus - 11 months ago 119
Linux Question

Installing packages with Anaconda

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

file from the TensorFlow website, and then ran
pip install foo.whl
. After this, I ran
pip freeze
, and it showed me
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
that comes with the native Ubuntu installation. However, I have the line
export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH
in my
file, and so this suggests it would use Anaconda's pip.

Any idea what's going on? Thanks!

Answer Source

You can try the similar answer here: http://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