Pip Quickstart

A quickstart guide for the python build tool pip.

Pip provides package management for the Python language. It’s main package repository is pypy.

Installing Pip

Pip is installed by default on most Linux distributions, but if it’s not installed you can install it using your package manager:

Fedora

sudo dnf install -y pip

Using Pip

Pip can install packages globally or on a user by user basis. Using pip to do package management at the system level isn’t generally recommended, but some distributions can handle it correctly.

If possible, use the python packages provided by your distribution rather than installing globally using pip. These may contain pre-compiled code (in the case of python modules that use c code) or distribution-spesific setup steps.

User-level packages

You can tell pip to install packages for the current user only. This does not require root privilages and can prove useful in locked down environments.

pip install --user packagename

If the package provides binaries or entry points, these will be placed in ~/.local/bin, you may need to adjust your $PATH to look in this directory.

Development mode packages

If you are working on a package designed to be used by other modules, or as a command line app, it can be useful to install the package in development mode.

This mode means changes to your code will be reflected when other applications try to use it (rather than installing the version from the python package archive).

cd ~/path/to/project
pip install -e .

This will create the required files in ~/.local/bin, but will link them with your project folder.

Virtual environments ( no pipenv )

Python has support for virtual environments, these are self-contained copies of modules used by an application. They allow you to install dependencies at a project-level rather than an os or user level.

Creating a virtual environment

TODO

Using an existing virtual environment

Once created, you can activate a virtual enviroment by invoking the activate file inside the virtual enviroment’s bin folder.

$ source .venv/bin/activate

# install requirements
$ pip install -r requirements.txt

Now when you run python commands, it will use the virtual enviroment rather than your system or user version. This allows you to make sure that you’ve not used a dependency but not declared it, or test out different versions of your dependencies.

about 400 Words.