Debianizing Python 程序以获得 .deb [重复]

2024-01-03

Aim

创建一个可安装的.deb文件(或包)。单击该按钮将在 Linux 计算机上安装该软件,并且图标将放置在 GNOME 面板上。以便从那里启动该应用程序。

我所提到的

我参考了两个 debianizing 指南。

Guide 2 http://wiki.debian.org/IntroDebianPackaging#Introduction_to_Debian_Packaging

第一个有一段无法理解的视频,部分是因为口音,部分是因为它已经过时了。(2007年上传)

第二个完全是文本。我直到第四步,构建包。但是当我这样做时,我得到的输出与指南中给出的内容不匹配。

我需要什么

我有一个简单的 python 程序。它会获取您的年龄,然后打印出您的年龄是否低于、等于或高于 18 岁。该程序只有一个文件,没有其他依赖项。我想把它建成.deb.

Specs

-Python 2.7

-Linux Mint

Edit

我按照您的指示遵循了确切的目录结构。并更换了全部myscript with cowsandbulls。构建完成,我得到了 Debian。当我安装它然后运行命令时cowsandbulls从终端我收到以下错误:

Traceback (most recent call last):
  File "/usr/bin/cowsandbulls", line 9, in <module>
    load_entry_point('cowsandbulls==1.0', 'gui_scripts', 'cowsandbulls')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 337, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2311, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2017, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
ImportError: No module named cowsandbulls

我刚刚测试过stdeb (see https://pypi.python.org/pypi/stdeb https://pypi.python.org/pypi/stdeb),一个 Python 包,用于将任何其他 Python 包转换为 Debian 包。

首先我安装了 stdeb:

apt-get install python-stdeb

然后我做了一个简单的脚本叫做myscript.py包含以下内容:

def main():
    print "Hello world, says myscript!"
    # wait for input from the user
    raw_input()

if __name__ == '__main__':
    main()

重要的是,您的目录结构应该是:

somewhere/myscript/
    setup.py
    myscript/
        __init__.py
        myscript.py

在 setup.py 文件中,您可以执行以下操作:

import os
from setuptools import setup
from nvpy import nvpy

setup(
    name = "myscript",
    version = "1.0",
    author = "Charl P. Botha",
    author_email = "[email protected] /cdn-cgi/l/email-protection",
    description = "Demo of packaging a Python script as DEB",
    license = "BSD",
    url = "https://github.com/cpbotha/nvpy",
    packages=['myscript'],
    entry_points = {
        'console_scripts' : ['myscript = myscript.myscript:main']
    },
    data_files = [
        ('share/applications/', ['vxlabs-myscript.desktop'])
    ],
    classifiers=[
        "License :: OSI Approved :: BSD License",
    ],
)

The console_scripts指令很重要,它将创建一个名为的可执行脚本my_script,在安装生成的 DEB 后,它将在系统范围内可用。如果你的脚本使用类似的东西tkinter or wxpython并且有图形用户界面,您应该使用gui_scripts代替console_scripts.

The data_files指令将安装一个合适的桌面文件到/usr/share/applications,这样您也可以开始myscript从您的桌面环境。vxlabs-myscript.desktop看起来像这样:

[Desktop Entry]
Version=1.0
Type=Application
Name=myscript
Comment=Minimal stdeb example
# myscript should wait for user input at the end, else the terminal
# window will disappear immediately.
Exec=myscript
Icon=/usr/share/icons/gnome/48x48/apps/file-manager.png
Categories=Utility;
# desktop should run this in a terminal application
Terminal=true
StartupNotify=true
StartupWMClass=myscript

要构建 DEB,您需要在顶层执行以下操作myscript:

python setup.py --command-packages=stdeb.command bdist_deb

这将在 deb_dist 目录中创建一个 .deb。

安装了我这样创建的 DEB 后,我可以运行myscript从命令行,我也可以从桌面环境调用它。

这是一个 GitHub 存储库,其中包含上面的示例代码:https://github.com/cpbotha/stdeb-minimal-example https://github.com/cpbotha/stdeb-minimal-example

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Debianizing Python 程序以获得 .deb [重复] 的相关文章

随机推荐