How to Install Some Project from PyPI, VCS, and some other sources with python3 pip

Published on Aug. 22, 2023, 12:12 p.m.

Pip is recommended installer.You need to make sure you have pip available.You can test this by running:

python3 -m pip --version

Installing from PyPI

The most common usage of pip is to install from the Python Package Index.

To install the latest version of “Some Project” on your computer:

python3 -m pip install "SomeProject"

To install a specific version, install the following :

python3 -m pip install "SomeProject==1.4"

To install more than or equal to one version and less than another :

python3 -m pip install "SomeProject>=1,<2"

To install a version that is compatible with a certain version.In this case, this means to install any version of the “1.4.4” version that’s also “4.2”.

python3 -m pip install "SomeProject~=1.4.2"

Requirements files

Put a list of requirements in a requirements file.

python3 -m pip install -r requirements.txt

Installing from VCS

VCS will install a project from VCS in “editable”.

python3 -m pip install -e git+https://git.repo/some_pkg.git#egg=SomeProject          # from git
python3 -m pip install -e hg+https://hg.repo/some_pkg#egg=SomeProject                # from mercurial
python3 -m pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomeProject         # from svn
python3 -m pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomeProject  # from a branch

Installing from other Indexes

python3 -m pip install --index-url http://my.package.repo/simple/ SomeProject

In addition to PyPI , search an additional index during installation.

python3 -m pip install --extra-index-url http://my.package.repo/simple SomeProject

Installing from a local src tree

Installing from local src in Development Mode, i.e. in such a way that the project appears to be installed, but yet is still editable from the tree of origin.

python3 -m pip install -e <path>

You can install normally from src.

python3 -m pip install <path>

Installing from local archives

python3 -m pip install ./downloads/SomeProject-1.0.4.tar.gz

python3 -m pip install --no-index --find-links=file:///local/dir/ SomeProject
python3 -m pip install --no-index --find-links=/local/dir/ SomeProject
python3 -m pip install --no-index --find-links=relative/dir/ SomeProject

Installing from other sources

To install from other data sources (for example Amazon S3 storage) you can create a helper application that presents the data in a PEP 503 compliant index format.

./s3helper --port=7777
python -m pip install --extra-index-url http://localhost:7777 SomeProject

Installing “Extras”

Extras are optional “variants” of a package. They may include additional dependencies. They enable additional functionality from the package.If you wish to install an extra for a package which you know publishes one:

python3 -m pip install SomePackage[PDF]
python3 -m pip install SomePackage[PDF]==3.0
python3 -m pip install -e .[PDF]  # editable project in current directory