2

How can I add "double-click" shortcuts to my python application with setuptools?

I actively develop a program that is used in our lab by myself and a handful of less tech savvy people. I distribute the app via PyPI/setuptools packages, and currently a "gui_scripts" entry point which launches a Qt GUI. I'm aware of freezing options like py2exe/app, but prefer setuptools since it allows for faster testing and deployment within the lab.

I'm looking for a way to add some kind of application shortcut or start-menu entry for my program to make it simpler to access for those not used to a command line.

On windows python creates an exe file in the python bin, is there a way to automatically create a shortcut to this on the desktop upon install? Perhaps with a custom icon? Do I have any similar options for mac/linux as far as appearing in the launchpad?

Thank you for the help!

  • Funny, I would have expected there to be an answer to this already. I only found these two though: [batch files for windows](https://stackoverflow.com/questions/37219045/windows-run-python-command-from-clickable-icon) and [.desktop files for ubuntu](https://askubuntu.com/questions/611047/how-to-make-an-icon-to-enter-terminal-commands). I don't think it's a good idea to create the icon during each install by running some platform specific code in the `setup.py`. The icon should just point to the latest installation and execute it. – Arne Jun 21 '19 at 06:47

1 Answers1

0

Whereas it is not a setuptools feature, you might want to look into pyshortcuts package that creates shortcuts across the different operating systems:

from pyshortcuts import make_shortcut

make_shortcut('/home/user/bin/myapp.py', name='MyApp',
                        icon='/home/user/icons/myicon.ico')

https://pypi.org/project/pyshortcuts/

This library could be in turn combined with setuptools by running the script after the installation, as shown here:

Another option is to use the distutils which can create an installation file. Specifically setup.py bdist feature which allows for using a post-installation script which can make use of create_shortcut function.

https://docs.python.org/3/distutils/builtdist.html

Here is someone using it.

mateuszb
  • 742
  • 10
  • 21