87

I can't find the correct way to install a local directory as a python package using pip.

(venv) C:\(...)>pip install . --no-index
Ignoring indexes: http://pypi.python.org/simple/
Unpacking c:\users\fsantos\desktop\biskates.com\biskates\forks\django-pipeline
  Running setup.py egg_info for package from file:///(...)%5Cforks%5Cdjango-pipeline

Installing collected packages: django-pipeline
  Running setup.py install for django-pipeline

Successfully installed django-pipeline
Cleaning up...

(venv) C:\(...)>cd ..
(venv) C:\(...)>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pipeline
>>> pipeline.__file__
'C:\\(...)site-packages\\pipeline\\__init__.py'
>>>

As you can see pip just copied over the package to site-packages. How can I avoid this, and use the package directly from its source folder?

I'm trying to integrate django-pipeline into my Django project, but I want to add support for Django 1.4 first, so I forked and cloned my fork.

Fábio Santos
  • 3,899
  • 1
  • 26
  • 31

3 Answers3

181

I can also just use:

cd your-local-repo
pip install -e .

or

python setup.py install develop
silviomoreto
  • 5,629
  • 3
  • 30
  • 41
  • 1
    my purpose was only for development, bit this is a pretty good answer. This should also work on a requirements.txt in a virtualenv. – Fábio Santos Jul 18 '13 at 20:38
  • Awesome solution! How do I then uninstall when changes are merged into the main repo? – ken Jun 06 '16 at 06:53
  • 1
    @FábioSantos The `-e` was the only missing part in your story and you should mark this answer as the correct one IMO. – smido Apr 12 '18 at 20:46
  • Reading this years later, this is indeed the correct answer. Sorry it took me so long :) – Fábio Santos Feb 29 '20 at 11:47
  • 1
    the command should be `python setup.py develop` instead of `python setup.py install develop`. IOW, `install` should not be there. See https://setuptools.readthedocs.io/en/latest/userguide/development_mode.html – Lucas Apr 17 '21 at 18:11
104

If you're working in a venv, you can do this:

env/bin/pip install git+file:///path/to/your/git/repo

Or with a branch:

env/bin/pip install git+file:///path/to/your/git/repo@mybranch
n00dle
  • 5,949
  • 2
  • 35
  • 48
Quilt
  • 1,040
  • 1
  • 7
  • 4
  • 1
    The question was about installing an actual directory (because I was developing two very closely related projects and I wanted to code on both when debugging), but this is a nice reminder of what can be done! – Fábio Santos Nov 26 '14 at 03:44
  • Mike, thanks! This helped me a lot. I had some git+ssh private dependencies and the repository server went to maintenance. – volhv Mar 24 '18 at 17:17
  • It is very important to note that there are **3** `/` after `git+file:` – nanounanue Sep 25 '18 at 15:13
  • What is the advantage of `env/bin/pip` over the usual `python -m pip` ? – Matt VanEseltine Apr 07 '20 at 16:13
14

You can use pip or pipenv with the following command to install from a local git repo:

pip install git+file:///path/to/your/package#egg=package-name

Note that there are 3 slashes after file: here.

To install from a remote repo use:

pip install git+ssh://git@github.com:Username/Project.git

You can also specify a desired branch like so:

pip install git+ssh://git@github.com:Username/Project.git@master

I just rounded up the previous answers and comments from Quilt and nanounanue and this question. Also posted it here.

Danil
  • 3,348
  • 2
  • 20
  • 16