Python – install script to system

EDIT: This answer deals only with installing executable scripts into /usr/bin. I assume you have basic knowledge on how setup.py files work.

Create your script and place it in your project like this:

yourprojectdir/
    setup.py
    scripts/
        myscript.sh

In your setup.py file do this:

from setuptools import setup
# you may need setuptools instead of distutils

setup(
    # basic stuff here
    scripts = [
        'scripts/myscript.sh'
    ]
)

Then type

python setup.py install

Basically that’s it. There’s a chance that your script will land not exactly in /usr/bin, but in some other directory. If this is the case, type

python setup.py install --help

and search for --install-scripts parameter and friends.

Leave a Comment