`pipenv install -e .` 有什么作用以及如何使用它? [英] What does `pipenv install -e .` do and how to use it?
问题描述
pipenv
帮助文档写道:
将本地 setup.py 安装到您的虚拟环境/Pipfile:
Install a local setup.py into your virtual environment/Pipfile:
$ pipenv install -e .
$ pipenv install -e .
有人可以详细说明何时以及如何使用与 setup.py
相关的命令 pipenv install -e .
吗?
Can someone further elaborate when and how to use the command pipenv install -e .
in relation to setup.py
?
根据pipenv
,-e .
指的是可编辑的依赖项.但是,我无法理解给出的解释.有人能解释一下吗?
According to pipenv
, -e .
refers to editable dependencies. However, I am unable to understand the given explanation. Can someone explain this?
例如,在我在 pip
的 --user
目录中创建了一个简单的发行版包调用 mypkg
后,即~/mypkg
,使用命令:
For example, after I had created a simple distro package call mypkg
in my --user
directory in pip
, i.e.~/mypkg
, using commands:
$ pipenv shell
(mypkg-x985xH5M) $ python3 setup.py sdist bdist_wheel
(mypkg-x985xH5M) $ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
和 /mypkg
并具有以下文件结构:
and /mypkg
and has the following file structure:
/mypkg
|_ LICENSE
|_ README.md
|_ setup.py
|_ /mypkg
| |_ __init__.py
| |_ mypkg.py
|_ /dist
| |_ mypkg-0.0.1rc1.tar.gz
| |_ mypkg-0.0.1rc1-py3-none-any.whl
|_ /build
| |_ /bdist.linux-x86_64
| |_ /lib
| |_ /mypkg
| |_ __init__.py
| |_ mypkg.py
|_ /mypkg.egg-info
|_ dependency_links.txt
|_ entry_points.txt
|_ PKG-INFO
|_ SOURCES.txt
|_ top_level.txt
命令 $ pipenv install -e .
有什么作用?
推荐答案
通常,pip
(驱动 setup.py
或其他 符合 PEP 518 的构建工具) 将构建并安装一个 Python 项目,到 Python <代码>站点包代码>位置..py
和 .pyc
文件在此过程中被复制.
Normally, pip
(driving setup.py
or another PEP 518 compliant build tool) will build and install a Python project, into the Python site-packages
location. .py
and .pyc
files are copied over in this process.
这意味着,如果您在磁盘上有项目的本地副本,则不能仅编辑 .py
源文件并查看从 .py
加载相同文件的项目中反映的更改代码>站点包.
This means that if you have a local copy of the project on disk, you can't just edit the .py
source files and see the changes reflected in projects that load those same files from site-packages
.
-e
开关构建,然后在 site-packages
中安装一个指针文件,该文件自动将项目的位置添加到 Python 的模块搜索路径.现在加载模块将从磁盘位置加载它们,而不是从 site-packages
加载,并且每次运行使用它的 Python 项目时都会显示对文件的更改.请参阅 Python setup.py develop vs install 和 setup.py install 和 setup.py develop 之间的区别
The -e
switch builds, then installs a pointer file in site-packages
that automatically adds the location of the project to Python's module search path. Now loading the modules will load them from the on-disk location, not from site-packages
, and changes to the files will show up every time you run a Python project that uses it. See Python setup.py develop vs install and Difference between setup.py install and setup.py develop
.
只是告诉 pip
/pipenv
将当前工作目录作为要构建的项目的位置(setup.py
或 pyproject.toml
文件和 [build-system]
部分应该存在于该目录中).
.
just tells pip
/ pipenv
to take the current working directory as the location of the project to build (setup.py
or pyproject.toml
file with [build-system]
section should exist in that directory).
对于您的示例,在 ~/mypkg
中运行 pip install -e .
,这意味着将运行 python3 setup.py develop
,在 Pipenv 维护的 Python 3 virtualenv 的 site-packages
目录中添加一个 .egg-link
文件.在同一个 site-packages
目录中是一个 easy-install.pth
文件,更新后添加了 ~/mypkg
目录的完整路径.所有这一切意味着 Python 中的 import mypkg
将直接从 ~/mypkg/mypkg
包中导入代码,以及您对 .py
所做的任何更改code> 文件将直接可用.
For your example, running pip install -e .
in ~/mypkg
, it means python3 setup.py develop
will be run, adding a .egg-link
file in the site-packages
directory of the Python 3 virtualenv that Pipenv is maintaining. In the same site-packages
directory is a easy-install.pth
file that is updated to add the full path of the ~/mypkg
directory. All this means that import mypkg
in Python will import the code directly from the ~/mypkg/mypkg
package, and any changes you make to the .py
files there are going to be directly available.
这篇关于`pipenv install -e .` 有什么作用以及如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!