4

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?

1
  • just place it inside .bashrc? Commented Dec 17, 2015 at 9:05

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

In terminal:

gedit ~/.bashrc

then inside .bashrc:

alias myScript ='python path/to/script/run.py'

reload bash, and it should work

To be sure where you are executing your script, to now which file to edit, you can check this with Python:

>>> import platform
>>> platform.system()
'Linux'
>>> 

To check if it is Mac:

platform.mac_ver()

4 Comments

is there a way for me to know if the systems uses .bachrc (linux, ubuntu etc..) or .profile (Mac)
@AsafNevo I which way? even before you create alias? Or inside python script?
I want to make sure i'm adding the alias to right file.. so it should be from inside the python script
It depends, I'm a Fish Shell user, also someone may use zsh, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.