171

When I need to work on one of my pet projects, I simply clone the repository as usual (git clone <url>), edit what I need, run the tests, update the setup.py version, commit, push, build the packages and upload them to PyPI.

What is the advantage of using pip install -e? Should I be using it? How would it improve my workflow?

jpmelos
  • 3,283
  • 3
  • 23
  • 30
  • You would do this when wanting to use a specific tag or branch instead of what is in master. The use case for this can be maybe due to some breaking change that your application is not handling in the "newer" code you are pulling in. Or, you want to use a "frozen" version for now, because you have validated that your stack explicitly works with that particular tag. – idjaw Mar 05 '17 at 15:07
  • I had a question on stack overflow related to finding directory path, pip install -e . resolved the issue. Below is the link which might be helpful. – Basavaraj Lamani Jun 06 '19 at 06:03
  • Does this answer your question? [When would the -e, --editable option be useful with pip install?](https://stackoverflow.com/questions/35064426/when-would-the-e-editable-option-be-useful-with-pip-install) – LudvigH May 28 '21 at 08:19

3 Answers3

141

I find pip install -e extremely useful when simultaneously developing a product and a dependency, which I do a lot.

Example:

You build websites using Django for numerous clients, and have also developed an in-house Django app called locations which you reuse across many projects, so you make it available on pip and version it.

When you work on a project, you install the requirements as usual, which installs locations into site packages.

But you soon discover that locations could do with some improvements.

So you grab a copy of the locations repository and start making changes. Of course, you need to test these changes in the context of a Django project.

Simply go into your project and type:

pip install -e /path/to/locations/repo

This will overwrite the directory in site-packages with a symbolic link to the locations repository, meaning any changes to code in there will automatically be reflected - just reload the page (so long as you're using the development server).

The symbolic link looks at the current files in the directory, meaning you can switch branches to see changes or try different things etc...

The alternative would be to create a new version, push it to pip, and hope you've not forgotten anything. If you have many such in-house apps, this quickly becomes untenable.

andyhasit
  • 14,137
  • 7
  • 49
  • 51
  • is `/path/to/locations/repo` this the path to `setup.py` for `pip install -e /path/to/locations/repo`? – Charlie Parker Apr 22 '21 at 14:37
  • @CharlieParker it's the path to the directory containing the setup.py file, which should be setup as a package https://setuptools.readthedocs.io/en/latest/setuptools.html. – andyhasit Apr 26 '21 at 16:35
93

For those who don't have time:

If you install your project with an -e flag (e.g. pip install -e mynumpy) and use it in your code (e.g. from mynumpy import some_function), when you make any change to some_function, you should be able to use the updated function without reinstalling it.

aerin
  • 20,607
  • 28
  • 102
  • 140
48

pip install -e is how setuptools dependencies are handled via pip. What you typically do is to install the dependencies:

  • git clone URL
  • cd project
  • run pip install -e . or pip install -e .[dev]*

And now all the dependencies should be installed.

*[dev] is the name of the requirements group from setup.py


Other than setuptools (egg) there is also a wheel system of python installation. Both these systems are based on promise that no building and compilation is performed.

Robin Thoni
  • 1,651
  • 13
  • 22
prosti
  • 42,291
  • 14
  • 186
  • 151
  • is `/path/to/locations/repo` this the path to `setup.py` for `pip install -e /path/to/locations/repo`? what is `.` in your example? – Charlie Parker Apr 22 '21 at 14:37
  • @CharlieParker I believe it is being run from the same directory the setup.py is in. That is how I use it at least. I have in my Makefile a line called "local" and the command it runs is `pip install -e .` and assumes being in the directory with the setup.py – james-see Apr 18 '22 at 17:29
  • searched entire internet and found just here what pip install -e .[dev] does. Thank you /|\ – Vinit Khandelwal Jul 05 '23 at 11:05