简体   繁体   中英

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 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!

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM