How do I make a python script executable?

  1. Add a shebang line to the top of the script:

    #!/usr/bin/env python

  2. Mark the script as executable:

    chmod +x myscript.py

  3. Add the dir containing it to your PATH variable. (If you want it to stick, you’ll have to do this in .bashrc or .bash_profile in your home dir.)

    export PATH=/path/to/script:$PATH

Leave a Comment