sag*_*ise 87 python packaging scripts deb
我有一个想要作为 deb 包分发的 python 脚本。它是在 Unity 面板中显示本地日期的指示器。我确实按照从脚本或二进制文件创建 .deb 包,但我无法创建 deb 包,因为它失败了。
有人可以给我一个关于我应该做什么的分步说明吗?据我所知,这个脚本依赖于python-appindicator.
注意:
我不想要任何指向 Debian/Ubuntu 打包说明的链接。我见过他们中的大多数。我不觉得他们对初学者友好。
and*_*ing 92
下面是一个基本示例,说明 Python 脚本的源包的外观。虽然大多数打包教程都有点复杂,但如果您遇到问题,它们确实可以提供帮助。也就是说,我首先通过简单地查看 Debian 软件包来了解 Debian 打包的基础知识。apt-get source类似的东西并通过实例学习。
这是您的基本源包布局:
my-script/
-- myScript
-- debian/
-- changelog
-- copyright
-- compat
-- rules
-- control
-- install
Run Code Online (Sandbox Code Playgroud)
dch --create在目录中运行以创建格式正确的debian/changelog条目。
debian/copyright应如下所示:
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: myScript
Upstream-Contact: Name, <email@address>
Files: *
Copyright: 2011, Name, <email@address>
License: (GPL-2+ | LGPL-2 | GPL-3 | whatever)
Full text of licence.
.
Unless there is a it can be found in /usr/share/common-licenses
Run Code Online (Sandbox Code Playgroud)
debian/compat可以是:7
Debian/规则:
#!/usr/bin/make -f
%:
dh $@ --with python2
Run Code Online (Sandbox Code Playgroud)
请注意,之前必须有“制表符” dh $@ --with python2,而不是空格。
Debian/控制:
Source: my-script
Section: python
Priority: optional
Maintainer: Name, <email@address>
Build-Depends: debhelper (>= 7),
python (>= 2.6.6-3~)
Standards-Version: 3.9.2
X-Python-Version: >= 2.6
Package: my-script
Architecture: all
Section: python
Depends: python-appindicator, ${misc:Depends}, ${python:Depends}
Description: short description
A long description goes here.
.
It can contain multiple paragraphs
Run Code Online (Sandbox Code Playgroud)
Debian/安装:
myScript usr/bin/
Run Code Online (Sandbox Code Playgroud)
此文件指示将哪个文件安装到哪个文件夹中。
现在用 debuild --no-tgz-check
这将创建一个功能性 deb 包。Lintian 将发出一些关于缺少 orig.tar.gz 的警告,但除非您计划创建一个适当的上游项目来发布 tarball 版本,否则您现在可能只想忽略它。
小智 21
打开'control',输入如下,保存在DEBIAN上
Package: mypyscript
Version: 0.01
Architecture: all
Maintainer: your name<your mail id>
Installed-Size: 2
Depends: python-appindicator
Section: extras
Priority: optional
Homepage: your homepage
Description: describe
Run Code Online (Sandbox Code Playgroud)回到名为 mypyscript 的文件夹。打开“用户”。创建一个名为“bin”的文件夹。打开“bin”并将您的pythonscript文件粘贴到那里。
dpkg -b mypyscript。然后按回车键。在几秒钟内您的 deb 包已准备就绪 注意:请正确填写“控制”文件。不要使用撇号。它仅用于指示名称。
coc*_*mac 13
.deb从单个 Python 3 脚本制作包(2021 年更新)与其他答案相比,这个答案看起来(而且)很长/但是,与已接受的答案不同,它将适用于 Python 3,并且在 2021 年。此外,它不会产生大量警告,因为它包含所有要求,就像一个man页面。
以下是如何通过单个 Python 3 脚本制作 Debian 软件包(是的,它可以在 Ubuntu 上运行)。首先,我们来制作脚本。这将是一个简单的 hello-world 程序。命名该文件hello-world。将其放入名为 的文件夹中hello-world-1.0.0。将该hello-world-1.0.0文件夹放入第二个名为 的文件夹中work。不过,这里的目录结构有点……奇怪。debuild(我们用来构建包的工具)会将.deb文件放置在我们构建它的位置的上一个目录中,因此目录结构将如下所示:
从现在开始,除非另有说明,我将假设您在该work/hello-world-1.0.0目录中。
work/\n\xe2\x94\x9c\xe2\x94\x80 hello-world-1.0.0/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 hello-world\nRun Code Online (Sandbox Code Playgroud)\n请注意,我在文件名中使用了连字符,而不是下划线,因为 Debian 不希望在包名称中使用下划线。我还省略了文件扩展名,这很好,因为我在脚本顶部添加了一个 shebang。
\n这是我将用作示例的 Python 脚本。如上所述,它被命名hello-world(没有文件扩展名)。
work/\n\xe2\x94\x9c\xe2\x94\x80 hello-world-1.0.0/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 hello-world\nRun Code Online (Sandbox Code Playgroud)\n请参阅此堆栈溢出问题以了解其if __name__ = "__main__:"含义。根据这个问题, shebang 已包含在内。
首先,只需通过运行来确保代码可以工作:
\n$ chmod +x ./hello-world\n$ ./hello-world\nHello world!\nRun Code Online (Sandbox Code Playgroud)\n要构建该.deb文件,您需要安装git、devscripts、build-essential、lintian和pandoc软件包。我知道其中一些软件包是预先安装的,但我也希望本指南能够在 Debian 上运行,所以无论如何我都将它们包含在这里。您可以使用这些命令安装它们。
sudo apt-get update\nsudo apt-get install git devscripts build-essential lintian pandoc\nRun Code Online (Sandbox Code Playgroud)\n在hello-world-1.0.0文件夹内,创建一个名为 的文件夹debian。在其中创建一个名为 的文件夹source。同样直接在debian文件夹内创建以下文件changelog、compat、control、copyright、install和rules。在文件夹内debian/source创建一个名为format.
您的目录树现在应该如下所示
\nwork/\n\xe2\x94\x9c\xe2\x94\x80 hello-world-1.0.0/\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 debian/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 source/\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 format\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 changelog\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 compat\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 control\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 copyright\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 install\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 rules\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80 hello-world\nRun Code Online (Sandbox Code Playgroud)\n现在,了解这些文件的内容。我假设您直接位于该hello-world-1.0.0文件夹中。
debian/source/format
您基本上可以忽略这一点,但如果您想知道, Debian 文档中的\xc2\xa75.22对此进行了解释。
\n3.0 (native)\nRun Code Online (Sandbox Code Playgroud)\ndebian/changelog
该文件包含程序的变更日志hello-world。
hello-world (1.0.0) unstable; urgency=medium\n\n * Initial release:\n -- John Doe <johndoe@example.com> Sun, 28 Nov 2021 10:18:51 -0800\nRun Code Online (Sandbox Code Playgroud)\ndebian/compat
这设置了debhelper兼容性级别。请参阅Debian 文档中的\xc2\xa75.2
10\nRun Code Online (Sandbox Code Playgroud)\ndebian/control
apt这设置了诸如工具用来管理包的各种值。请参阅Debian 文档中的\xc2\xa74.1
Source: hello-world\nSection: python\nMaintainer: John Doe <johndoe@example.com>\nBuild-Depends: debhelper (>= 7),\n python3 (>= 3.5)\nStandards-Version: 4.5.1\nPriority: optional\n\nPackage: hello-world\nArchitecture: all\nSection: python\nDepends: python3 (>=3.5), ${misc:Depends}\nDescription: A simple hello-world program to demenstrate how to package a\n Python 3 script as a deb file\nRun Code Online (Sandbox Code Playgroud)\ndebian/copyright
该文件包含有关源代码的版权和许可的信息。在这里,我假设代码将遵循 MIT 许可证。根据需要更改此设置。请参阅Debian 文档中的\xc2\xa74.2
\nFormat: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n\nFiles: *\nCopyright: 2021 John Doe <johndoe@example.com>\nLicense: MIT-License\n\nFiles: debian/*\nCopyright: 2021 John Doe <johndoe@example.com>\nLicense: MIT-License\n\nLicense: MIT-License\n MIT License\n .\n Copyright (c) 2021 John Doe\n .\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the "Software"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n .\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n .\n THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\nRun Code Online (Sandbox Code Playgroud)\ndebian/install
此文件控制将哪些文件安装到您的包的位置。请参阅Debian 文档中的\xc2\xa75.11
\nhello-world usr/bin/\nhello-world.1 usr/share/man/man1/\nRun Code Online (Sandbox Code Playgroud)\ndebian/rules
这就是 Debian 构建软件包的方式。请参阅Debian 文档中的\xc2\xa74.4 。警告:像其他 Makefile 一样,使用制表符缩进。空格将不起作用。
\n#!/usr/bin/make -f\n\n%:\n dh $@\nRun Code Online (Sandbox Code Playgroud)\n我们漂亮的hello-world包应该有一个man页面。但手册页的格式很复杂且难以阅读。因此,我们将用 Markdown 编写手册页,并让pandoc我们帮您转换它。
在主目录(即直接在hello-world-1.0.0文件夹内)中,创建一个名为hello-world.1.md. 将以下内容放入文件中:
#!/usr/bin/env python3\ndef hello_world():\n print("Hello world!")\n\nif __name__ == "__main__":\n hello_world()\nRun Code Online (Sandbox Code Playgroud)\n构建这个和包需要几个步骤。因此,让我们创建一个 (Bash) 脚本来代替。创建一个名为build. 使其可执行chmod +x ./build。将以下内容放入文件中:
$ chmod +x ./hello-world\n$ ./hello-world\nHello world!\nRun Code Online (Sandbox Code Playgroud)\n这将生成手册页,并将其存储在名为hello-world.1. 然后它将构建该包。这-uc -us 意味着我们不会使用 GPG 密钥对其进行签名,因为这很复杂。运行脚本(./build),如果一切顺利的话,父目录下就会有生成的包work。
| 归档时间: |
|
| 查看次数: |
41721 次 |
| 最近记录: |