如何使用 Python distutils?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29562/
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
How to use Python distutils?
提问by Jiaaro
I wrote a quick program in python to add a gtk GUI to a cli program. I was wondering how I can create an installer using distutils. Since it's just a GUI frontend for a command line app it only works in *nix anyway so I'm not worried about it being cross platform.
我在 python 中编写了一个快速程序,将 gtk GUI 添加到 cli 程序。我想知道如何使用 distutils 创建安装程序。由于它只是命令行应用程序的 GUI 前端,因此它只能在 *nix 中运行,因此我不担心它是跨平台的。
my main goal is to create a .deb package for debian/ubuntu users, but I don't understand make/configure files. I've primarily been a web developer up until now.
我的主要目标是为 debian/ubuntu 用户创建一个 .deb 包,但我不了解 make/configure 文件。到目前为止,我主要是一名网络开发人员。
edit: Does anyone know of a project that uses distutils so I could see it in action and, you know, actually try building it?
编辑:有谁知道一个使用 distutils 的项目,所以我可以看到它的实际效果,你知道,实际上尝试构建它?
Here are a few useful links
这里有一些有用的链接
This Guide is veryhelpful. I don't know how I missed it during my initial wave of gooling. It even walks you through packaging up an existing python application
This is the official package maintaining project at ubuntu. Anyone can join, and there are lots of tutorials and info about creating packages, of all types, which include the above 'python packaging guide'.
"Python distutils to deb?" - Ars Technica Forum discussion
According to this conversation, you can't just use distutils. It doesn't follow the debian packaging format (or something like that). I guess that's why you need dh_make as seen in the Ubuntu Packaging guide
"A bdist_deb command for distutils
This one has some interesting discussion (it's also how I found the ubuntu guide) about concatenating a zip-file and a shell script to create some kind of universal executable (anything with python and bash that is). weird. Let me know if anyone finds more info on this practice because I've never heard of it.
Description of the deb format and how distutils fit in - python mailing list
本指南非常有帮助。我不知道在最初的谷歌热潮中我是如何错过它的。它甚至会引导您打包现有的 Python 应用程序
这是 ubuntu 的官方包维护项目。任何人都可以加入,并且有很多关于创建各种类型的包的教程和信息,其中包括上面的“python 打包指南”。
“Python distutils 到 deb?” - Ars Technica 论坛讨论
根据这个对话,你不能只使用 distutils。它不遵循 debian 打包格式(或类似格式)。我想这就是你需要 dh_make 的原因,如 Ubuntu Packaging 指南中所示
这个有一些有趣的讨论(这也是我如何找到 ubuntu 指南)关于连接一个 zip 文件和一个 shell 脚本来创建某种通用可执行文件(任何带有 python 和 bash 的)。奇怪的。如果有人发现有关这种做法的更多信息,请告诉我,因为我从未听说过。
采纳答案by Sander
See the distutils simple example. That's basically what it is like, except real install scripts usually contain a bit more information. I have not seen any that are fundamentally more complicated, though. In essence, you just give it a list of what needs to be installed. Sometimes you need to give it some mapping dicts since the source and installed trees might not be the same.
请参阅distutils 简单示例。这基本上就是它的样子,除了真正的安装脚本通常包含更多信息。不过,我还没有看到任何从根本上更复杂的东西。本质上,您只需给它一个需要安装的列表。有时你需要给它一些映射字典,因为源和安装的树可能不一样。
Here is a real-life (anonymized) example:
这是一个真实的(匿名)示例:
#!/usr/bin/python
from distutils.core import setup
setup (name = 'Initech Package 3',
description = "Services and libraries ABC, DEF",
author = "That Guy, Initech Ltd",
author_email = "[email protected]",
version = '1.0.5',
package_dir = {'Package3' : 'site-packages/Package3'},
packages = ['Package3', 'Package3.Queries'],
data_files = [
('/etc/Package3', ['etc/Package3/ExternalResources.conf'])
])
回答by Stuart Cardall
apt-get install python-stdeb
apt-get install python-stdeb
Python to Debian source package conversion utility
Python 到 Debian 源包转换实用程序
This package provides some tools to produce Debian packages from Python packages via a new distutils command, sdist_dsc. Automatic defaults are provided for the Debian package, but many aspects of the resulting package can be customized via a configuration file.
该软件包提供了一些工具,可通过新的 distutils 命令 sdist_dsc 从 Python 软件包生成 Debian 软件包。Debian 软件包提供了自动默认值,但生成的软件包的许多方面都可以通过配置文件进行自定义。
- pypi-install will query the Python Package Index (PyPI) for a package, download it, create a .deb from it, and then install the .deb.
- py2dsc will convert a distutils-built source tarball into a Debian source package.
- pypi-install 将在 Python 包索引 (PyPI) 中查询一个包,下载它,从中创建一个 .deb,然后安装 .deb。
- py2dsc 会将 distutils 构建的源 tarball 转换为 Debian 源包。
回答by Rusty Shackelford
回答by Andrew Wilkinson
Most Python programs will use distutils. Djangois a one - see http://code.djangoproject.com/svn/django/trunk/setup.py
大多数 Python 程序将使用 distutils。Django是一个 - 见http://code.djangoproject.com/svn/django/trunk/setup.py
You should also read the documentation, as it's very comprehensive and has some good examples.
您还应该阅读文档,因为它非常全面并且有一些很好的例子。
回答by Jason Baker
distutils really isn't all that difficult once you get the hang of it. It's really just a matter of putting in some meta-information (program name, author, version, etc) and then selecting what files you want to include. For example, here's a sample distutils setup.py module from a decently complex python library:
一旦你掌握了它,distutils 真的不是那么困难。这实际上只是输入一些元信息(程序名称、作者、版本等)然后选择要包含的文件的问题。例如,这里有一个来自相当复杂的 python 库的示例 distutils setup.py 模块:
Note that this doesn't deal with any data files or or whatnot, so YMMV.
请注意,这不处理任何数据文件或诸如此类的东西,所以 YMMV。
On another note, I agree that the distutils documentation is probably some of python's worst documentation. It is extremely inclusive in some areas, but neglects some really important information in others.
另一方面,我同意 distutils 文档可能是 Python 最糟糕的文档之一。它在某些领域非常具有包容性,但在其他领域却忽略了一些非常重要的信息。