Conflicts when installing Anaconda Python

2019-04-10 23:57发布

I have recently installed the Anaconda distribution of Python. I then inserted the following line into my .bashrc file:

export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH

So, there are now two python binary files: one in /usr/bin/, and one in /home/karnivaurus/Libraries/Anaconda/bin.

I also have a python script, which attempts to import a module named caffe, with the line import caffe. Now, if I run python caffe from the terminal, the script runs fine. However, if I open the script in PyCharm, and set the interpreter to be /home/karnivaurus/Libraries/Anaconda/bin/python, I get the following error:

ImportError: No module named caffe

Based on all this, I have two questions....

  1. If I run the python command from the terminal, which binary file would it execute? The one in /usr/bin, or the one in /home/karnivaurus/Libraries/Anaconda/bin? My intuition is that it runs the first one, due to the discrepancy in behaviour with PyCharm. In that case, how can I force my system to use the Anaconda version?

  2. If I install a new package, for example pip install caffe, then where will it be installed to? Will it be installed to /usr/local/lib/python2.7/site-packages, or to /home/karnivaurus/Libraries/Anaconda/pkgs? How can I be sure that my python command will know where to find the new package?

Thank you!

1条回答
forever°为你锁心
2楼-- · 2019-04-11 00:50

Answer to 1:

Based on your example: export PATH=/home/karnivaurus/Libraries/Anaconda/bin:$PATH the /home/karnivaurus/Libraries/Anaconda/bin comes first, so the python from there should be the one to be executed.

But the definite answer depends on result of running: which python.

Answer to 2:

In Anaconda, use conda instead of pip to install packages. When you install using pip install caffe you'll be installing to /usr/local/lib/python2.7/site-packages.

Use conda install caffe to install to /home/karnivaurus/Libraries/Anaconda/pkgs.


Above two answers explain why even if you pip install spam package, python would say ImportError: No module named spam. Essentially you install to ordinary Python, but you attempt to import in Anaconda's python.

查看更多
登录 后发表回答