'Where does Python search for modules after installing Anaconda?
Previously, I have been using Python 2.7. If I installed a module using pip, it would place the module in /usr/local/lib/python2.7/site-packages
. Then, if I were to import
that module in a python script, the site-packages
directory would be searched to find that module.
However, I want to start using the Anaconda distribution. After downloading this, I notice that there are a number of packages located at /home/karnivaurus/Anaconda/pkgs
, for example scikit-learn
. Then, in the directory of each packages, there is the directory structure lib/python2.7/site-packages
, which contains the modules for that package.
So, it seems that I have now gone from the situation where I only had one site-packages
directory, to where I have a number of site-packages
directories, one for each package.
My question is: When I create a python script, and want to import a module, how does python know where to look for these modules? Will it look in /usr/local/lib/python2.7/site-packages
as well as the site-packages
directories that come with Anaconda? What if I want to install another package that does not come with Anaconda -- where should this be installed to?
Thanks!
Solution 1:[1]
The paths in which Python will import packages can be seen with the following command:
python -c "import sys; print sys.path"
Please see the documentation, also (as stated in the documentation) if you need to modify the search path, look into PYTHONPATH.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | iLoveTux |