Practical Data Science Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

The following steps will show you how to download a Python package and install it from the command line:

  1. Download the source code for the package in the place you like to keep
    your downloads.
  2. Unzip the package.
  3. Open a terminal window.
  4. Navigate to the base directory of the source code.
  5. Type in the following command:
python setup.py install 
  1. If you need root access, type in the following command:
sudo python setup.py install 

To use pip, the contemporary and easiest way to install Python packages, follow these steps:

  1. First, let's check whether you have pip already installed by opening a terminal and launching the Python interpreter. At the interpreter, type:
>>>import pip 
  1. If you don't get an error, you have pip installed and can move on to step 5. If you see an error, let's quickly install pip.
  2. Download the get-pip.py file from https://raw.github.com/pypa/pip/master/contrib/get-pip.py onto your machine.
  3. Open a terminal window, navigate to the downloaded file, and type:
python get-pip.py 

Alternatively, you can type in the following command:

sudo python get-pip.py 
  1. Once pip is installed, make sure you are at the system command prompt.
  2. If you are using the default system distribution of Python, type in the following:
pip install networkx 

Alternatively, you can type in the following command:

sudo pip install networkx 
  1. If you are using the Anaconda distribution, type in the following command:
conda install networkx 
  1. Now, let's try to install another package, ggplot. Regardless of your distribution, type in the following command:
pip install ggplot 

Alternatively, you can type in the following command:

sudo pip install ggplot