为 python 项目构建一个轮子/鸡蛋和所有依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26059111/
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-08-18 23:59:03  来源:igfitidea点击:

Build a wheel/egg and all dependencies for a python project

pythonwindowseggpython-wheel

提问by Salim Fadhley

In order to stage python project within our corporation I need to make an installable distribution.

为了在我们公司内上演 python 项目,我需要制作一个可安装的发行版。

This should include:

这应该包括:

  • An egg or whl for my project
  • An egg or whl for every dependency of the project
  • (optionally) produce a requirements.txt file listing all the installable components for this release
  • 我的项目的鸡蛋或 whl
  • 项目的每个依赖项的蛋或 whl
  • (可选)生成一个 requirements.txt 文件,列出此版本的所有可安装组件

Is there an easy plug in, (e.g. an alternative to bdist_wheel) that will not only compile one wheel but also that project's components?

是否有一个简单的插件(例如 bdist_wheel 的替代品),它不仅可以编译一个轮子,还可以编译该项目的组件?

Obviously I can script this, but I was hoping that there might be a short-cut that builds the package + dependencies in fewer steps.

显然我可以编写这个脚本,但我希望可能有一个捷径,可以在更少的步骤中构建包 + 依赖项。

This needs to work on Python 2.7 on Windows + Linux.

这需要在 Windows + Linux 上的 Python 2.7 上运行。

采纳答案by Mike Driscoll

You will need to create a setup.pyfile for your package. Make sure you have the latest setuptools and pip installed. Then run the following:

您需要setup.py为您的包创建一个文件。确保您安装了最新的 setuptools 和 pip。然后运行以下命令:

python setup.py bdist_wheel

This will create a wheel file for your package. This assumes you don't have C/C++ headers, DLLs, etc. If you do, then you'll probably have a lot more work to do.

这将为您的包创建一个轮文件。这假设您没有 C/C++ 头文件、DLL 等。如果您有,那么您可能有更多的工作要做。

To get dependencies, you will want to create a requirements.txtfile and run the following:

要获取依赖项,您需要创建一个requirements.txt文件并运行以下命令:

pip wheel -r requirements.txt

If your package isn't on PyPI, then you'll have to manually copy your package's wheel file into the wheel folder that this command creates. For more information see the following excellent article:

如果您的包不在 PyPI 上,那么您必须手动将包的轮文件复制到此命令创建的轮文件夹中。有关更多信息,请参阅以下优秀文章:

回答by jtpereyda

With the latest pipand wheel, you can simply run

使用最新的pipand wheel,您只需运行

pip wheel .

within your project folder, even if your application isn't on PyPi. All wheels will be stored in the current directory (.).

在您的项目文件夹中,即使您的应用程序不在 PyPi 上。所有轮子都将存储在当前目录 ( .) 中。

To change the output directory (to for example, ./wheels), you may use the -w / --wheel-diroption:

要更改输出目录(例如,./wheels),您可以使用以下-w / --wheel-dir选项:

pip wheel . -w wheels

All the options available are listed at the pip documentation.

pip 文档中列出了所有可用选项。