为 python 项目构建一个轮子/鸡蛋和所有依赖项 [英] Build a wheel/egg and all dependencies for a python project

查看:24
本文介绍了为 python 项目构建一个轮子/鸡蛋和所有依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这应该包括:

  • 我的项目的鸡蛋或 whl
  • 项目的每个依赖项的蛋或 whl
  • (可选)生成一个 requirements.txt 文件,列出此版本的所有可安装组件

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

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?

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

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

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

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

推荐答案

使用 poetry 你可以定义你的项目根目录下的文件中关于项目的依赖项和元数据,名为 pyproject.toml:

With poetry you can define your dependencies and metadata about your project in a file in the root of your project, called pyproject.toml:

[tool.poetry]
name = "my-project"
version = "0.1.0"
description = "some longer description"
authors = ["Some Author <some@author.io>"]

[tool.poetry.dependencies]
python = "*"

[tool.poetry.dev-dependencies]
pytest = "^3.4"

要将项目构建为轮子,请执行 poetry build

To build your project as a wheel, execute poetry build

$ poetry build

Building my-project (0.1.0)
- Building sdist
- Built my-project-0.1.0.tar.gz

- Building wheel
- Built my-project-0.1.0-py3-none-any.whl

一个 dist/ 文件夹是为您的项目创建的.

a dist/ folder is created with a wheel for your project.

这篇关于为 python 项目构建一个轮子/鸡蛋和所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆