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.
Table of Contents
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://%MINIFYHTMLcc774846afec283805e9e867d67ae3f47%/<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
- How to Configure a BIND Server on Ubuntu - March 15, 2018
- What is a BGP Confederation? - March 6, 2018
- Cisco – What is BGP ORF (Outbound Route Filtering)? - March 5, 2018
Want to become a programming expert?
Here is our hand-picked selection of the best courses you can find online:
Python Zero to Hero course
Python Pro Bootcamp
Bash Scripting and Shell Programming course
Automate with Shell Scripting course
The Complete Web Development Bootcamp course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial