When would the -e, --editable option be useful with pip install?

前端 未结 4 677
悲哀的现实
悲哀的现实 2020-11-29 00:07

When would the -e, or --editable option be useful with pip install?

For some projects the last line in requirements.txt is

4条回答
  •  粉色の甜心
    2020-11-29 00:55

    From Working in "development" mode:

    Although not required, it’s common to locally install your project in “editable” or “develop” mode while you’re working on it. This allows your project to be both installed and editable in project form.

    Assuming you’re in the root of your project directory, then run:

    pip install -e .

    Although somewhat cryptic, -e is short for --editable, and . refers to the current working directory, so together, it means to install the current directory (i.e. your project) in editable mode.

    Some additional insights into the internals of setuptools and distutils from “Development Mode”:

    Under normal circumstances, the distutils assume that you are going to build a distribution of your project, not use it in its “raw” or “unbuilt” form. If you were to use the distutils that way, you would have to rebuild and reinstall your project every time you made a change to it during development.

    Another problem that sometimes comes up with the distutils is that you may need to do development on two related projects at the same time. You may need to put both projects’ packages in the same directory to run them, but need to keep them separate for revision control purposes. How can you do this?

    Setuptools allows you to deploy your projects for use in a common directory or staging area, but without copying any files. Thus, you can edit each project’s code in its checkout directory, and only need to run build commands when you change a project’s C extensions or similarly compiled files. You can even deploy a project into another project’s checkout directory, if that’s your preferred way of working (as opposed to using a common independent staging area or the site-packages directory).

    To do this, use the setup.py develop command. It works very similarly to setup.py install, except that it doesn’t actually install anything. Instead, it creates a special .egg-link file in the deployment directory, that links to your project’s source code. And, if your deployment directory is Python’s site-packages directory, it will also update the easy-install.pth file to include your project’s source code, thereby making it available on sys.path for all programs using that Python installation.

提交回复
热议问题