Sometimes, a particular python package or script that you wanted to install may not available in Python Package Index (PyPI). Even if that package is available in PyPI, a new feature of that package may not be available. So, you can't install it using Pip package manager on your Linux box. In such cases, you can easily install those packages directly from its official GitHub repository. This brief guide explains how to install Python packages from GitHub on Linux and other Unix-like distributions.
Make sure you have installed git and pip on your Linux system. Both packages are available in the default repositories of most Linux distributions.
To install git on Arch Linux and its variants like Manjaro Linux, run:
$ sudo pacman -S git
On Debian, Ubuntu:
$ sudo apt install git
On Fedora, CentOS, RHEL:
$ sudo dnf install git
$ sudo zypper install git
To install Pip, refer the following guide:
Install Python Packages From GitHub On Linux
Pip supports installing from Git, Mercurial, Subversion and Bazaar, and detects the type of VCS using URL prefixes like: git+, hg+, svn+, and bzr+. Pip currently supports cloning over;
- and git+file
For the purpose of this guide, I will be using "eg", a Python client to access tldr pages.
To install eg python package from GitHub, simply run:
$ pip install git+https://github.com/srsudar/eg.git
Collecting git+https://github.com/srsudar/eg.git Cloning https://github.com/srsudar/eg.git to /tmp/pip-80a8bmyb-build Installing collected packages: eg Running setup.py install for eg ... done Successfully installed eg-1.1.1
You can include egg=<projectname> part at the end of the above command to explicitly name the project. This way pip can track metadata for it without having to have run the setup.py script.
$ pip install git+https://github.com/srsudar/eg.git#egg=eg
You can also pass a branch name, a commit hash, a tag name or a git ref when installing packages from github. For instance, the following command will install the python package from master branch.
$ pip install git+https://github.com/srsudar/[email protected]#egg=eg
Another way to install a Python package from GitHub is to Git clone the repository:
$ git clone https://github.com/srsudar/eg.git
And then cd in to the project directory:
$ cd eg
Finally, run the following command to install it:
$ sudo python setup.py install
$ sudo pip install -e .
What if I don't have Git on my system?
Just in case, you don't have git installed on your Linux system, install the python package by mentioning the full path of its tarball file like below.
$ pip install https://github.com/srsudar/eg/archive/v1.1.1.tar.gz
Hope this helps.