Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Python script accessible system wide

Can someone tell me how to make my script callable in any directory?

My script simply returns the number of files in a directory. I would like it to work in any directory by invoking it, instead of first being copied there and then typing python myscript.py

I am using Mac OS X, but is there a common way to get it installed on Windows and Linux?

like image 272
Ali Avatar asked Feb 14 '26 05:02

Ali


1 Answers

If your script starts with a suitable shebang line, such as:

#!/usr/bin/env python

And your script has the executable bit set (for Linux, OS X, and other Unix-like systems):

chmod +x myscript.py

And the path to your script is in your PATH environment variable:

export PATH=${PATH}:`pwd` # on Unix-like systems

SET PATH=%PATH%;\path\to # on Windows

Then you can call myscript.py from wherever you are.

like image 106
Johnsyweb Avatar answered Feb 16 '26 18:02

Johnsyweb



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!