Open In App

How to install a Python Package from a GitHub Repository

Improve
Improve
Like Article
Like
Save
Share
Report

In this article we will learn how to install a pip package from a git repository, PIP supports installing from various version control systems (VCS). This support requires a working executable to be available (for the version control system being used). It is used through URL prefixes:

  •    Git — git+
  •    Mercurial — hg+
  •    Subversion — svn+
  •    Bazaar — bzr+

Install pip package from a Git repository

How pip install it from a git repository

Initially install, pip will Clone the repository and fetch and check out the desired commit than it will build the package into a wheel it install that wheel and their dependencies (if any).

To install the PIP package run the following command

Syntax: pip install "Package" @ git+"URL of the repository"
pip install pip@git+https://github.com/pypa/pip

Output:

Since the PIP package comes with the default installation of Python when we try to install pip from the GIT repository it shows that the Requirement is already satisfied.

How to install a Python Package from a GitHub Repository

 

Installing specified PIP version

Here, you have to replace the version commit with the git commit of the version you want to install, later in this article, we will see how to install from commits and subdirectories and name the project also.

pip install pip@git+https://github.com/pypa/pip@'version commit'

Output:

In the output image, we can clearly see that first the version of pip was 22.2.1 and after installing the specified new commit version it is changed to 23.0

How to install a Python Package from a GitHub Repository

 

Installing NumPy from GIT Repository

pip install GFG@git+https://github.com/numpy/numpy
How to install a Python Package from a GitHub Repository

 

Installing the pyClip from the GIT repository

pip install clip@git+https://github.com/spyoungtech/pyclip
How to install a Python Package from a GitHub Repository

 

You can see that package is installed successfully.

Install Specific Project from a GitHub Repository

For specifying the “project name” use #egg=<pkg_name> and add it at the end.

pip install "Package" @ git+"URL of the repository#egg=<pkg_name>"

For example, installing NumPy.

pip install GFG @ git+https://github.com/numpy/numpy#egg=Numpy

For example, installing an emoji module.

pip install emoji@git+https://github.com/carpedm20/emoji#egg=EMOJI
How to install a Python Package from a GitHub Repository

 

Install Subdirectory of the GitHub Repository

If the project you want to install is in a subdirectory of the repository not on the root, in that case, add #subdirectory=<path> at the end

pip install "Package" @ git+"URL of the repository#subdirectory=path"

For example, installing the NumPy subdirectory:

pip install GFG @ git+https://github.com/numpy/numpy#subdirectory=numpy

Last Updated : 28 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads