如何在Mac上制作Python可执行文件? [英] How do you make a Python executable file on Mac?

查看:1362
本文介绍了如何在Mac上制作Python可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Google搜索使我失败了.我想知道如何在OS X上制作可执行的Python文件,也就是说,如何制作可以通过双击(而不是从外壳程序)启动Python脚本的.exe文件.为此,我认为不同脚本语言之间的解决方案是相似的,是这样吗?

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?

推荐答案

要使Shell中的脚本文件(例如Python)可执行,您需要在文件的第一行中加入所谓的hash-bang行(调整为您的python二进制文件的位置):

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

然后,您还需要通过运行例如chmod u+x <name_of_the_script.file>.

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>.

完成这些步骤后,您可以直接从Terminal运行程序.

After these steps you can run the program directly from Terminal.

./<name_of_the_script.file>

这篇关于如何在Mac上制作Python可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆