简体   繁体   中英

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. 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? 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. 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 .

For your specific question about creating a menu entry or a desktop shortcut, you want a .desktop file .

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. 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.

If you're using linux just use aliases . 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. In terminal you would write 'runpy'. Also add a alias for this file to create a alias :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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