Python packages have a file that allows to easily install it while handling the dependencies.

To install a package, you commonly use the pip install command. For example, to install numpy you run the following command:

(example_env) qdouasbin@jolly:~/Python_envs>pip install numpy
Collecting numpy
  Downloading (24.5MB)
    100% |████████████████████████████████| 24.5MB 35kB/s 
Installing collected packages: numpy
Successfully installed numpy-1.15.4

If you now run the pip list command it shows you that the numpy library has been added to the Python virtual environment:

(example_env) qdouasbin@jolly:~/Python_envs>pip list
numpy (1.15.4)
pip (9.0.3)
setuptools (39.0.1)

By default pip is trying to install from the Pypi:

The Python Package Index (PyPI) is a repository of software for the Python programming language. PyPI helps you find and install software developed and shared by the Python community. Package authors use PyPI to distribute their software.

You can also install packages from a local repository as long as it contains a file.

For example, let’s download a GitHub repository and pip install it from the local repository. Here is the GitHub page of the project: sampleproject on GitHub

(example_env) qdouasbin@jolly:~/Python_envs>cd ~/
(example_env) qdouasbin@jolly:~>git clone
Cloning into 'sampleproject'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 348 (delta 3), reused 3 (delta 0), pack-reused 336
Receiving objects: 100% (348/348), 82.45 KiB | 654.00 KiB/s, done.
Resolving deltas: 100% (169/169), done.
(example_env) qdouasbin@jolly:~>cd sampleproject/
(example_env) qdouasbin@jolly:~/sampleproject>ls -l
total 64
-rw-r--r--  1 qdouasbin  3000  1081 15 nov 15:11 LICENSE.txt
-rw-r--r--  1 qdouasbin  3000   133 15 nov 15:11
-rw-r--r--  1 qdouasbin  3000  1705 15 nov 15:11
drwxr-xr-x  3 qdouasbin  3000    96 15 nov 15:11 data
drwxr-xr-x  4 qdouasbin  3000   128 15 nov 15:11 sample
-rw-r--r--  1 qdouasbin  3000   664 15 nov 15:11 setup.cfg
-rw-r--r--  1 qdouasbin  3000  8302 15 nov 15:11
drwxr-xr-x  4 qdouasbin  3000   128 15 nov 15:11 tests
-rw-r--r--  1 qdouasbin  3000  1150 15 nov 15:11 tox.ini

The file contains the all the information needed to install the package. For example, it contains the list of the depedencies to install for the project sampleproject to work. For instance, it contains the following line:


Which tells us that the package peppercorn is needed and will be installed when installing sampleproject. We can install this project using pip install .:

(example_env) qdouasbin@jolly:~/sampleproject>pip install .
Processing /Users/qdouasbin/sampleproject
Collecting peppercorn (from sampleproject==1.2.0)
Installing collected packages: peppercorn, sampleproject
  Running install for sampleproject ... done
Successfully installed peppercorn-0.6 sampleproject-1.2.0
(example_env) qdouasbin@jolly:~/sampleproject>pip list
numpy (1.15.4)
peppercorn (0.6)
pip (9.0.3)
sampleproject (1.2.0)
setuptools (39.0.1)
(example_env) qdouasbin@jolly:~/sampleproject>

We can see that sampleproject and peppercorn have been installed. The line Running install for sampleproject ... done tells us more about the installation mechanism used here: the pip install command actually run a python install command.

Using the latter command gives more freedom and has a special feature to develop a library. Let’s uninstall the sampleproject and peppercorn library.

(example_env) qdouasbin@jolly:~/sampleproject>pip uninstall peppercorn sampleproject
Uninstalling peppercorn-0.6:
Proceed (y/n)? y
  Successfully uninstalled peppercorn-0.6
Uninstalling sampleproject-1.2.0:
Proceed (y/n)? y
  Successfully uninstalled sampleproject-1.2.0

We can install the sampleproject library and its dependencies (namely peppercorn) using either the python install or the python develop

  • The python install command will copy the compiled files in your python virtual environnement folder. This is equivalent to using pip install . (as pip install . actually runs the python install command!).
  • The python develop command will create a symbolic link from the library to your python virtual environnement folder. This allows you to code your library while using it from anywhere on your system.

Like this post? Share on: TwitterFacebookEmail

Keep Reading





Stay in Touch