Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use case for `pip install -e`?

Tags:

python

pip

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?

like image 468
jpmelos Avatar asked Mar 05 '17 15:03

jpmelos


People also ask

What is the use of pip install?

The pip install <package> command always looks for the latest version of the package and installs it. It also searches for dependencies listed in the package metadata and installs them to ensure that the package has all the requirements that it needs.

What does pip install -- upgrade do?

You can run “pip install --upgrade pip” to install and use the new version of pip. To update pip2 or pip3 using this command, only replace the first pip with the pip version.

What does U flag do with pip?

1 Answer. This option upgrades all packages. From man pip /INSTALL OPTIONS: -U, --upgrade Upgrade all packages to the newest available version.

What does Conda install pip do?

pip is the standard package manager for python, meaning you can use it both inside and outside of Anaconda. It allows you to install and manage additional packages that are not part of the Python Package Index (PyPI).


1 Answers

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.

like image 84
andyhasit Avatar answered Oct 01 '22 14:10

andyhasit