python PIP:仅安装依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2317410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-04 00:21:23  来源:igfitidea点击:

PIP: Installing only the dependencies

pythonpipvirtualenvdistribute

提问by muhuk

I have a script that creates a virtualenv, installs distributeand pipin it and then optionally clones a gitrepo.

我有一个脚本,可以创建一个virtualenv,安装distributepip在其中,然后可以选择克隆一个gitrepo。

Now I have the project I will be working on, installed. But its dependencies are not installed. How can I make pipinstall all the dependencies as if I have issued a pip install MyApp?

现在我已经安装了我将要处理的项目。但是没有安装它的依赖项。如何pip安装所有依赖项,就像我已经发布了一样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-packagesthough.

不太确定,但pip install -e .似乎可以做我想做的事情,而没有太多额外的东西。如果我的代码没有链接,我更喜欢site-packages

采纳答案by muhuk

In my package root issuing pip install -e .installs dependencies.

在我的包根发行pip install -e .安装依赖项。

回答by Jakub Kukul

If your dependencies are defined in the setup.pyfile, you can first dump them to an external file using:

如果您的依赖项在setup.py文件中定义,您可以首先使用以下命令将它们转储到外部文件:

python setup.py egg_info

This will list all your dependencies in YOUR_PROJECT.egg-info/requires.txtfile. Then you can install them using pip:

这将列出YOUR_PROJECT.egg-info/requires.txt文件中的所有依赖项。然后您可以使用pip以下方法安装它们:

pip install -r *.egg-info/requires.txt

回答by Lakshman Prasad

You should use the pip requirements file.

您应该使用 pip 要求文件。

Essentially, place all your requirements, one in each line in a file and pass that to pip using the command

本质上,将所有需求放在文件中的每一行中,然后使用命令将其传递给 pip

pip install -r requirements.txt

What more, if you have a standard environment, pip can actually dump such a file from existing installs using the command:

更重要的是,如果您有一个标准环境,pip 实际上可以使用以下命令从现有安装中转储这样的文件:

pip freeze

You can put the file thus generated directly into the pip requirements, and call the previous command from your deployment script.

您可以将这样生成的文件直接放入 pip 需求中,并从您的部署脚本中调用之前的命令。

Pretty cool, isnt it? :)

很酷,不是吗?:)

回答by jfaleiro

To install your project's dependencies (i.e. install_requires+ extra_requires) you have to extract your dependencies using setuptools egg-infoand then install the filtered list of the combined dependencies:

要安装项目的依赖项(即install_requires+ extra_requires),您必须使用 setuptools 提取依赖项egg-info,然后安装组合依赖项的过滤列表:

python setup.py egg_info
pip install `grep -v '^\[' *.egg-info/requires.txt`