简体   繁体   English

如何从python脚本在Ubuntu中创建可执行文件+启动器?

[英]How create an Executable file + Launcher in Ubuntu from a python script?

I have created a simple program in python. 我用python创建了一个简单的程序。 Now I want trasform this script in an executable program ( with hidden source code if possible ) and when I click 2 times on it, the program install itself on the ubuntu ( in the /usr/lib or /usr/bin I think ) and it will create a new launcher in the Application -> Game menu. 现在,我想在一个可执行程序(如果可能的话,带有隐藏的源代码)中转换此脚本,当我单击它两次时,该程序将自己安装在ubuntu上(在我认为的/ usr / lib或/ usr / bin中),然后它将在“应用程序”->“游戏”菜单中创建一个新的启动器。

How can I do that ? 我怎样才能做到这一点 ?

Closed-source? 闭源? Meh. 咩。 Well, you can compile python iirc, or simply use an obscusificator. 好了,您可以编译python iirc,或仅使用obscusificator。 But I recommend to open-source it ;-) The stuff you can double-click are .desktop files, for samples, see find /usr | grep desktop 但是我建议将其开源;-)您可以双击的东西是.desktop文件,有关示例,请参见find /usr | grep desktop find /usr | grep desktop . find /usr | grep desktop

I can't help you with concealing the python source, however, the application launcher is a Desktop Entry file with a .desktop extension. 我无法帮助您隐藏python源,但是,应用程序启动器是带有.desktop扩展名的Desktop Entry文件。 Your installer would install that to the applications folder in one of the system XDG_DIRS such as /usr/share/ or /usr/local/share . 您的安装程序会将其安装到系统XDG_DIRS之一(例如/usr/share//usr/local/shareapplications文件夹中。

If you install your application's icon to a theme friendly location (such as /usr/local/share/icons/hicolor/<size>/apps/<your application name>.png ) and install your executable to a location in PATH (often /usr/bin or /usr/local/bin ) then you desktop entry file would not need absolute paths to the executable or icon. 如果将应用程序的图标安装到主题友好的位置(例如/usr/local/share/icons/hicolor/<size>/apps/<your application name>.png ),然后将可执行文件安装到PATH中的位置(通常是/usr/bin/usr/local/bin ),则您的桌面条目文件将不需要指向可执行文件或图标的绝对路径。

As an example, let's take a python application called "myapp.py". 例如,让我们以一个名为“ myapp.py”的python应用程序为例。 Here is it's .desktop file: 这是.desktop文件:

[Desktop Entry]
Name=My Application
Type=Application
Exec=myapp.py
Icon=myapp

Then say the application is built with autotools ( configure , make , make install ) with the "default" build options in which prefix=/usr/local/share . 然后说该应用程序是使用自动工具( configuremakemake install )和“ default”构建选项构建的,其中prefix=/usr/local/share The following files would be installed: 将安装以下文件:

/usr/local/share/applications/myapp.desktop
/usr/local/share/icons/hicolor/16x16/apps/myapp.png
# same for sizes 22x22, 24x24, 32x32, 48x48, 64x64
# it's also a good idea to include a "scalable" svg icon
/usr/local/bin/myapp  
# ^ this is your python "executable"

After running update-desktop-database as root (or from your Makefile) then your application will have a launcher and a nice pretty icon. 以root用户(或从Makefile)运行update-desktop-database后,您的应用程序将具有启动器和漂亮的漂亮图标。

use pyinstaller from pyinstaller.org 使用来自pyinstaller.org的pyinstaller

http://bytes.com/topic/python/insights/579554-simple-guide-using-pyinstaller http://bytes.com/topic/python/insights/579554-simple-guide-using-pyinstaller

pyinstaller helloworld.py pyinstaller helloworld.py

creates 2 folders bin and dist 创建2个文件夹bin和dist

run your exec form dist folder like 运行您的exec形式dist文件夹

./helloworld 。/你好,世界

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Windows上开发的Python脚本在Mac上创建可执行文件 - How to create executable file on mac from python script developed on windows 如何从Python 3脚本创建独立的可执行文件? - How to create a standalone executable file from Python 3 script? 如何从 Windows 中的 Python 脚本创建可在 Mac 上运行的可执行文件? - How to create an executable from a Python script in Windows that can run on a Mac? 适用于 Windows 的 python 启动器:如何设置 python 可执行文件? - python launcher for windows: how to set python executable? 如何从python 3.5脚本创建独立的可执行文件? - How to create standalone executable file from python 3.5 scripts? 如何从 python 脚本为所有 windows 创建可执行文件? - How to create an executable file from python scripts for all windows? 如何从 Mac 上的另一个可执行文件/Python 脚本调用可执行文件? - How to make a call to an executable from another executable/Python script on Mac? 如何从Python脚本调用可执行文件? - How to make a call to an executable from Python script? 如何为python程序创建可执行文件 - How to create a executable file to a python program 为什么我不能从我的 Python 脚本创建可执行文件? - Why can't I create an executable from my Python script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM