问题
My google searching has failed me. I'd like to know how to make an executable Python file on OS X, that is, how to go about making an .exe file that can launch a Python script with a double click (not from the shell). For that matter I'd assume the solution for this would be similar between different scripting languages, is this the case?
回答1:
To make a script file (such as Python) executable from a shell, you need to include so called hash-bang line as the first line of the file (adjust to your location of python binary):
#!/usr/local/bin/python
Then you also need to make the file executable by setting the execute bit by running e.g. chmod u+x <name_of_the_script.file>.
After these steps you can run the program directly from Terminal.
./<name_of_the_script.file>
回答2:
You can run python scripts through OS X Terminal. You just have to write a python script with an editor, open your Terminal and enter python path_to_my_script/my_script.py
来源:https://stackoverflow.com/questions/29584270/how-do-you-make-a-python-executable-file-on-mac