Making Python script accessible system wide

霸气de小男生 提交于 2019-11-29 08:23:49

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.

All of those operating systems should support a PATH environment variable which specifies directories that have executables that should be available everywhere. Make your script executable by chmod +x and place it into one of those directories (or add a new one to your PATH - I have ~/bin for instance).

I don't know how to make new kinds of files directly executable on Windows, though, but I guess you could use a .bat file as a proxy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!