简体   繁体   English

我如何像包管理器那样安装python脚本呢?

[英]How do i install a python script like package manager does?

If i try to install a package from package manager in any kind of Linux based system, it is installed, adds a shortcut to system menu and so on. 如果我尝试在任何类型的基于Linux的系统中从软件包管理器安装软件包,它将被安装,添加系统菜单的快捷方式等等。 It removes the whole package if i type: 如果我输入,它将删除整个包:

"sudo apt autoremove 'packagename'"

How can i do that kind of stuff for my own python script? 我怎么能为我自己的python脚本做那种东西? How is it possible to create a shortcut and install the script for my own system? 如何为我自己的系统创建快捷方式并安装脚本? So i can quickly access it from system menu and uninstall it with one command as i want? 所以我可以从系统菜单快速访问它并使用一个命令卸载它,因为我想要? I dont want to add a shortcut manually or dont want to distribute my program in a repository, just want it to act like a regular packaged program. 我不想手动添加快捷方式或者不想在存储库中分发我的程序,只是希望它像普通的打包程序一样。

The "package" contains dozens of small distro-specific configuration snippets and scripts to integrate the packaged program with the rest of the system. “包”包含许多小的特定于发行版的配置片段和脚本,以将打包的程序与系统的其余部分集成。 Some parts of this are specified in distro-neutral standards such as http://freedesktop.org/ but the most accessible documentation will probably be in the packaging manual for your particular distro. 其中一些部分是在中间版标准中指定的,例如http://freedesktop.org/,但是最易于访问的文档可能会出现在您的特定发行版的包装手册中。 For Debian and derivatives (Mint, Ubuntu, etc) the authoritative documentation will be the Debian Developers' Reference, but you might want to start with the Debian Wiki "Packaging" page . 对于Debian和衍生产品(Mint,Ubuntu等),权威文档将是Debian开发人员参考,但您可能想要从Debian Wiki“Packaging”页面开始

For your specific question about creating a menu entry or a desktop shortcut, you want a .desktop file . 有关创建菜单项或桌面快捷方式的特定问题,您需要一个.desktop文件

Creating a .deb file for a simple Python scipt and a .desktop file for it is eventually a fairly simple task, but getting a grasp of the entire stack from Python packaging basics to distributing it from a simple PPA or local file system is probably going to take some effort. 为一个简单的Python scipt和.desktop文件创建一个.deb文件最终是一个相当简单的任务,但是从Python打包基础知识到从简单的PPA或本地文件系统分发它的整个堆栈可能正在进行要付出一些努力。 If you already have a correct setup.py file, the next step would probably be to wrap it with a simple debhelper package, then add a .desktop file once you have that working. 如果你已经有一个正确的setup.py文件,下一步可能是用一个简单的debhelper包来包装它,然后在你运行之后添加一个.desktop文件。

If you're using linux just use aliases . 如果你正在使用linux,只需使用别名。 That is the easiest way . 这是最简单的方法。 alias aliasname='commands'

#!/usr/bin/python


import os

def alias_writer(bashrc, a_name, a_command):
    with open(bashrc, 'a') as bash_profile:
        bash_profile.write('alias ' + a_name+'='+a_command+'\n')
    os.system("source " + bashrc)

alias_writer('/Users/user/.bash_profile', 'runpy', 'python')

That write a alias 'runpy' and runs the python console. 写一个别名'runpy'并运行python控制台。 In terminal you would write 'runpy'. 在终端你会写'runpy'。 Also add a alias for this file to create a alias :) 还为此文件添加别名以创建别名:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM