Skip to main content
 首页 » 编程设计

python之如何像 bdist_wininst 一样使用 bdist_rpm

2025年05月04日8powertoolsteam

我正在构建一个 Tkinter 应用程序并将其分发到 centos 和 win7

win7打包时

python setup.py bdist_wininst --install-script script_to_create_shortcut.py 

在开始菜单和桌面上与启动器配合使用效果非常好

但对于 CentOS

python setup.py bdist_rpm --install-script script_to_create_shortcut_for_linux.py 

惨败

后来我意识到 rpm 需要 sh 文件才能执行,所以我使用了安装后脚本

python setup.py bdist_rpm --post-install=script_to_create_shortcut_for_linux.py 

失败,因为它也是存储在 sh 文件中的 python 代码

现在,我编写了一个运行 python -c "from module import post_install_script" 的 sh 文件 但这也失败了,因为安装后脚本找不到正确的函数名称

setup.py

setup=(.. 
      scripts=[os.path.join('tickets','complaints.py'), 
               os.path.join('tickets','shortcut_linux.py'), 
               os.path.join('tickets','tickets.svg')], 
...) 

快捷方式创建者或安装后 python 脚本

        file_created(os.path.join(sys.prefix,'bin','complaints.py')) 
        desktop=get_special_folder_path("CSIDL_COMMON_DESKTOPDIRECTORY") 
        startmenu=get_special_folder_path("CSIDL_COMMON_STARTMENU") 
        create_shortcut(os.path.join(sys.prefix,'bin','complaints.py'), 
                        "Complaints Register", 
                        os.path.join(desktop,'complaints.desktop'), 
                        '','', 
                        os.path.join(sys.prefix,'bin','tickets.svg')) 
        file_created(os.path.join(desktop,'complaints.desktop')) 
        create_shortcut(os.path.join(sys.prefix,'bin','complaints.py'), 
                        "Complaints Register", 
                        os.path.join(startmenu,'complaints.desktop'), 
                        '','', 
                        os.path.join(sys.prefix,'bin','tickets.svg')) 

失败,错误为全局名称 file_created 未定义...

为什么rpm没有wininst那么简单,wininst什么都做的很简单

我在这背后花了太多时间...任何帮助将不胜感激 谢谢

注意:对于 wininst,快捷方式文件有不同的路径 eg:it dint had 'bin'

请您参考如下方法:

你是在Windows/CentOs中构建rpm吗?如果是centos系统,你需要安装rpm-build package来构建rpm 使用 ->

python setup.py bdist_rpm

所以首先,使用命令安装 rpm-build 包 ->

yum 安装 rpm-build

然后,运行命令->

python setup.py bdist_rpm