The thing to know here is that many Pythons can live in one computer... and when installing a package you need to know which Python are you installing it on. People usially install many "Python environments" (or virtualenvs
) in one computer, to allow them to monkey around in one Python without the risk of breaking something in the others.
In these tutorials we use the Anaconda Python distribution, which is (almost) always installed in its own virtualenv
in the Anaconda directory.
In Windows, Anaconda is often installed in:
C:\Users\Diego\Anaconda
Mac and Linux, Anaconda is normally installed in:
/home/diego/anaconda
Anaconda comes with its own package installer called conda. If you are using Anaconda, using conda
is the easiest way to install modules. However, not all packages can be installed using conda
, see List of Packages for a list of all avalilable packages (note that some come pre-installed).
Note that conda
will install the packages in the directory where Anaconda
lives, and those packages may only be available to the Anaconda Python (and not to system-wide Python and/or other virtualenv environments).
Example:
Supose we want to install the package called basemap. Simply open a terminal (or in Windows, the Anaconda Command Promt) and type:
conda install basemap
pip is a program to install Python packages. It is very popular! Each Python in your computer has its own pip
, therefore you need to know which pip
you need to use.
First identify the pip
you want to use... in this case the pip
of your anaconda Python. In Mac or Linux, it should be here:
/home/diego/anaconda/bin/pip
In windows it should be here:
C:\Users\Diego\Anaconda\Scripts\pip
Example:
Supose we want to install the package called Pydap...
In Windows type in the 'Anaconda Command Promt':
C:\Users\Diego\Anaconda\Scripts\pip install Pydap
In Mac or Linux, type in a terminal:
/home/diego/anaconda/bin/pip install Pydap
Every Python should have a setup.py
file. This file is used to install the package. pip
and conda
use these setup.py
files to install packages in your computer for you. However, not all packages have been uploaded to the pip
and conda
repositories. Those have to be installed manually... and again, the trick is to use the "correct" Python.
In the example below, we still want to install a package in the Anaconda Python, but it is not available with conda
nor with pip
...
Example:
To install the package called UTide...
First step: Download package
Download the package from the package's webpage (or repository)... in this case UTide. Note that packages are formed by many files. Sometime all the fiels are downloaded in a single "zipped" or compressed file. If so, you will need to "unzip" the file after you downloaded it.
Second step: Install package
Open a terminal (Mac or Linux) or an Anaconda Command Promt
(Windows) and dive into the directory containing the packages files (i.e. where the setup.py is located). This is achived with the cd
command... for example:
cd C:\Users\Diego\Downloads\UTide
then...
In Windows type in the 'Anaconda Command Promt':
C:\Users\Diego\Anaconda\python setup.py install
In Mac or Linux, open a terminal and type:
/home/diego/anaconda/bin/python setup.py install
In [ ]: