Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python create system alias to script

Tags:

python

sh

I creating an install script for my python project which installs all the external dependencies I need in order to run properly.

I want to create a system alias named myScript which will be alias for path/to/script/run.py so users could just run it by using myScript command

How can I do it?

like image 748
Asaf Nevo Avatar asked Oct 16 '25 04:10

Asaf Nevo


1 Answers

If your project has a setup.py script and you're installing your python packages, scripts, and dependencies using setuptools (and you should be), you can use the entry_points feature of setuptools.

setup.py

from setuptools import setup

setup(
    # other arguments here...
    entry_points={
        'console_scripts': [
            'myScript = my_package.run:main',
        ],
    },
)

Your project structure should look like this:

setup.py
/my_package
    __init__.py
    run.py

Your run.py script should have a main() function, which will get run when someone types myScript at the command line. This works regardless of what shell they use or what platform you're on.

like image 155
Brendan Abel Avatar answered Oct 17 '25 19:10

Brendan Abel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!