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.
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.
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