
上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:
- Download the source code for the package in the place you like to keep
your downloads. - Unzip the package.
- Open a terminal window.
- Navigate to the base directory of the source code.
- Type in the following command:
python setup.py install
- 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:
- 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
- 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.
- Download the get-pip.py file from https://raw.github.com/pypa/pip/master/contrib/get-pip.py onto your machine.
- 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
- Once pip is installed, make sure you are at the system command prompt.
- 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
- If you are using the Anaconda distribution, type in the following command:
conda install networkx
- 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