PIP:仅安装依赖项
我有一个脚本,它创建一个 virtualenv
,在其中安装 distribute
和 pip
,然后选择性地克隆一个 git
存储库。
现在我已经安装了我将要处理的项目。但它的依赖项没有安装。如何让 pip
安装所有依赖项,就像我发出 pip install MyApp
一样?
编辑:显然我的问题与这个。
不太确定,但是 pip install -e .
似乎可以做我想做的事情,而没有太多额外的东西。不过,我希望我的代码没有从 site-packages
链接。
I have a script that creates a virtualenv
, installs distribute
and pip
in it and then optionally clones a git
repo.
Now I have the project I will be working on, installed. But its dependencies are not installed. How can I make pip
install all the dependencies as if I have issued a pip install MyApp
?
EDIT: Appareantly my question is a duplicate of this one.
Not exactly sure but pip install -e .
seems to do what I want without too many extra stuff lying around. I'd prefer if my code wasn't linked from site-packages
though.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您的依赖项在
setup.py
文件中定义,您可以首先使用以下方法将它们转储到外部文件:这将在
YOUR_PROJECT.egg-info/requires.txt< 中列出您的所有依赖项/代码> 文件。然后您可以使用
pip
安装它们:删除您刚刚创建的内容:
以节省一些时间复制粘贴:
If your dependencies are defined in the
setup.py
file, you can first dump them to an external file using:This will list all your dependencies in
YOUR_PROJECT.egg-info/requires.txt
file. Then you can install them usingpip
:to delete what you just created:
to save some time copy pasting:
在我的包根目录中发出
pip install -e .
安装依赖项。In my package root issuing
pip install -e .
installs dependencies.您可以使用 pip-tools 创建一个
requirements.txt
仅包含您的包的依赖项:请注意,上述命令仅在您还没有
requirements.txt
文件时才有效。如果您碰巧已经有一个,请将其删除。然后,您可以使用生成的
requirements.txt
运行 pip 来安装依赖项:好处 1:
requirements.txt
将包含指示相关依赖项源自何处的注释。奖励 2:
如果您的
setup.py
中有一个用于可选依赖项的extras_require
部分,如下所示:您可以创建
requirements.txt 通过使用以下方式包含可选的依赖项:
You can use pip-tools to create a
requirements.txt
that only contains the dependencies of your package:Note that the command above only works if you do not already have a
requirements.txt
file. If you happen to have one already, just delete it.Using the generated
requirements.txt
you can then run pip to install the dependencies:Bonus 1:
The
requirements.txt
will include comments that indicate where the regarding dependency originates from.Bonus 2:
If you have have an
extras_require
section for optional dependencies in yoursetup.py
that looks e.g. like this:You can create the
requirements.txt
including the optional dependencies by using:要安装项目的依赖项(即
install_requires
+extra_requires
),您必须使用 setuptoolsegg-info
提取依赖项,然后安装过滤后的列表组合的依赖关系:To install your project's dependencies (i.e.
install_requires
+extra_requires
) you have to extract your dependencies using setuptoolsegg-info
and then install the filtered list of the combined dependencies:您应该使用 pip 要求文件。
本质上,将所有要求放在文件中的每一行中,然后使用命令将其传递给 pip
更重要的是,如果您有标准环境,pip 实际上可以使用以下命令从现有安装中转储这样的文件:
您可以将将因此生成的文件直接添加到 pip 要求中,并从部署脚本中调用前面的命令。
很酷,不是吗? :)
You should use the pip requirements file.
Essentially, place all your requirements, one in each line in a file and pass that to pip using the command
What more, if you have a standard environment, pip can actually dump such a file from existing installs using the command:
You can put the file thus generated directly into the pip requirements, and call the previous command from your deployment script.
Pretty cool, isnt it? :)