fir3net
PPS-Firenetbanner-780.5x190-30-03-17

How to install a Git Repo using Pip

Pip is a package management system used to install and manage software packages written in Python [1]. Its easy to use and provides an excellent way to deploy your code with minimal fuse.
Within this article we will show you how to install a git repo [2] directly via pip.

Setup.py

First of all add a setup.py file to your repo. This file will be read by pip at the point of installation.
Note : If you code is located within folders use the packages keyword instead of py_modules.

from setuptools import setup

setup(
    name="<program_name>",
    version="<version>",
    author_email="<email>",
    description="<description>,
    py_modules = ['<filename>']
)

Additional documentation around building a setup.py file can be found here.

Installation

Once done you can then install.
To install via SSH the following syntax is used,

sudo pip install git+ssh://This email address is being protected from spambots. You need JavaScript enabled to view it./<username>/<repo_name>.git

To install via HTTPS the following syntax is used,

sudo pip install git+https://github.com/<username>/<repo_name>.git

Example

Install

# pip install git+https://github.com/felix001/threader.git
Downloading/unpacking git+https://github.com/felix001/threader.git
  Cloning https://github.com/felix001/threader.git to /tmp/pip-jrlnNB-build
  Running setup.py egg_info for package from git+https://github.com/felix001/threader.git

Installing collected packages: threader
  Running setup.py install for threader

Successfully installed threader
Cleaning up...

Confirm Install

# pip show threader
---
Name: threader
Version: 1.0
Location: /opt/lib/python2.7/site-packages
Requires:

Requirements.txt

You may be now asking yourself "How is the module that I have installed from Git included within my requirements file?".
To ensure the correct entry is included within your requirements file add the egg switch to your pip command. Like so,

pip install -e git+https://github.com/felix001/commontools.git#egg=commontools

If you now run a git freeze you will see the correct entry,

# pip freeze
Django==1.10.2
-e git+https://github.com/felix001/commontools.git@aabb915dff035d243bb91df3461c632d7a366ceb#egg=commontools
django-sslserver==0.19
djangorestframework==3.4.7
pymongo==3.3.0
wsgiref==0.1.2

References

[1] https://en.wikipedia.org/wiki/Pip_%28package_manager%29
[2] https://github.com/felix001/threader

Tags: Python, Github, pip

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001