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

邮差的信 提交于 2020-05-07 10:12:52

问题


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?

If this helps, here are my two pet projects that I currently package and send to PyPI, but never used pip install -e. One is pure Python, the other is a Django package.

  • https://github.com/jpmelos/subcomm
  • https://github.com/jpmelos/django-generic-models

How would the project's workflow or structure be improved by using pip install -e?


回答1:


Using pip install -e . can actually be useful if you want to run your packages with python package.py and you import other modules of your project from that file. The command makes them findable!

What it does is:

  • installs site-packages/PackageName.egg-link file
  • adds path to site-packages/easy-install.pth
  • optionally installs CLI targets in <venv>/bin

It seems either of the earlier two is sufficient, and the latter is handy when developing command-line utilities.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/42609943/what-is-the-use-case-for-pip-install-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!