Trying use a .pth file to add a path in documents folder on Mac

核能气质少年 提交于 2019-12-06 09:23:36

Forget the .pth stuff for now, that's not something you'd normally do. In a unix-ish environment, the typical way you'd run a script would be to change directory:

 cd /Users/Ben/Documents/Python/

and then run the script:

python chaos.py

Another way to do it would be to run the script with an absolute path; you can do this no matter your current working directory:

python /Users/Ben/Documents/Python/chaos.py

Finally, if you've written a utility script you want to be run from anywhere without typing that absolute path all the time, you can do something a little fancier...

Add a 'shebang' line as the first line of your script. It'll go like this:

#!/usr/bin/env python

Get into the directory where your script lives:

cd /Users/Ben/Documents/Python/

Make the script executable:

chmod +x chaos.py

Put a link to the script in a directory on your path... /usr/local/bin/ could be a good choice:

ln -s /Users/Ben/Documents/Python/chaos.py /usr/local/bin/chaos.py

Now you can type chaos.py anywhere on your system and it'll run.

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