Steps to install a Git cloned package locally with pip

Overview

A note on how to install packages from a locally cloned Git repository rather than from a remote PyPI (Python Package Index) with the pip command.

The following environment is assumed, but I think that the same operation can be performed in the Linux environment.

Motivation

If you're writing an application of some size in Python, you may want to make changes to the packages you installed with pip. If you rewrite the code directly at that time, it is difficult to undo the change, and it is difficult to return the change upstream.

You can solve this problem if you can treat the locally cloned Git (or Mercurial) repository as a Python package and install it with pip.

procedure

Clone the Python package to a suitable path. Let's clone Django under / tmp.

cd /tmp && git clone [email protected]:django/django.git

Create a suitable Virtualenv under $ HOME. If you are using Python 2.x, replace pyvenv with virtualenv and read.

pyvenv ~/dummy-project
source ~/dummy-project/bin/activate

Install the cloned Django with pip.

pip install -e /tmp/django

Now let's see what happens to Django's django-admin.py installed here.

cat ~/dummy-project/bin/django-admin.py
#!/Users/aeas44/dummy-project/bin/python3.4
# EASY-INSTALL-DEV-SCRIPT: 'Django==1.9.dev20150318000307','django-admin.py'
__requires__ = 'Django==1.9.dev20150318000307'
import sys
from pkg_resources import require
require('Django==1.9.dev20150318000307')
del require
__file__ = '/private/tmp/django/django/bin/django-admin.py'
if sys.version_info < (3, 0):
    execfile(__file__)
else:
    exec(compile(open(__file__).read(), __file__, 'exec'))

Of note is the line __file__ ='/ private / tmp / django / django / bin / django-admin.py'. On MacOSX, / tmp is symbolically linked to / private / tmp, which means that Django, which was cloned to / tmp earlier, is the reality.

By editing the repository cloned to / tmp, your changes will be reflected in your project without having to reinstall. If you want, you can commit your changes and bring them back upstream.

Recommended Posts

Steps to install a Git cloned package locally with pip
Steps to install your own library with pip
I want to install a package from requirements.txt with poetry
How to install mysql-connector with pip3
What to do if you get a UnicodeDecodeError with pip install
I want to pip install with PythonAnywhere
How to install a package using a repository
I can't install the package with pip.
Steps to create a Twitter bot with python
Load a package created locally with Go Module
I failed to install django with pip, so a reminder of the solution
How to install pip
Install scikit.learn with pip
I want to install a package of Php Redis
A memorandum when an error occurs with pip install
[Introduction to Python] What is the recommended way to install pip, a package management system?
How to install NPI + send a message to line with python
Can't find the package you installed with pip install --user?
I made a package to filter time series with python
When moss with pip install
Get the package version to register with PyPI from Git
Install github repository with pip
What to do if you can't install pyaudio with pip #Python
I get an error when trying to install maec 4.0.1.0 with pip
Install packages that need to be compiled with Python3 with pip [Windows]
[TensorFlow] If you want to run TensorBoard, install it with pip
Steps to develop Django with VSCode
Steps to install MySQL 8.0 on CentOS 8.1
Install Python 2.7.9 and Python 3.4.x with pip.
A memo to move Errbot locally
What to do with Magics install
Steps to create a Django project
Permission denied with pip install pyopenssl
Steps to install Ubuntu in VirtualBox
How to create a Conda package
Steps to install VirtualBox on CentOS
Easy to install pyspark with conda
Manipulate colors with pip install color
Unable to install Python with pyenv
Steps to install python3 on mac
How to install Anaconda with pyenv
[Python Windows] pip install with Python version
I got stuck trying to install various things with Mac El captain pip, so make a note
PyPi debut I tried to pip install a library to check Japanese holidays
How about creating a virtual environment with Anaconda and doing pip install?
Steps to create a Python virtual environment with VS Code on Windows
How to install python package in local environment as a general user
Deb package development with Git: (Part 1) Creating a stray package with the minimum configuration
What to do if you can't install with pip in babun environment
Install the python module with pip on a server without root privileges
Build Linux on a Windows environment. Steps to install Laradock and migrate
Steps to build a Django environment with Win10 WSL Ubuntu18.04 + Anaconda + Apache2
SSL certificate related with pip install? Error
Install Python as a Framework with pyenv
How to create a git clone folder
Update package with pip standard features only
Python installation and package management with pip
How to install DLIB with 2020 / CUDA enabled
`pip install pygraphviz` fails to find graphviz
How to prevent package updates with apt
I was addicted to pip install mysqlclient