如果已经安装了py2app 0.2.x或者更早的版本,我们需要先卸载老版本,可以使用脚本来卸载:
#!/usr/bin/env python
import os, shutil
from distutils.sysconfig import *
py2app = os.path.join(get_python_lib(), 'py2app')
import shutil
if os.path.isdir(py2app):
print "Removing " + py2app
shutil.rmtree(py2app)
if os.path.exists(py2app + '.pth'):
print "Removing " + py2app + '.pth'
os.unlink(py2app + '.pth')
for path in os.environ['PATH'].split(':'):
script = os.path.join(path, 'py2applet')
if os.path.exists(script):
print "Removing " + script
os.unlink(script)
执行改脚本的时候可能需要使用:sudo
我安装py2app的时候是使用的 easy_install 这个工具,安装该工具的方法:
curl -O http://peak.telecommunity.com/dist/ez_setup.py
$ sudo python ez_setup.py -U setuptools
然后使用 easy_install 安装 py2app :
sudo easy_install -U py2app
1、进入工程目录下面: cd yourProjectDirctory
2、生成 setup.py 文件: py2applet --make-setup MyApplication.py
3、清空以前生成的编译文件: rm -rf build dist
4、生成mac下的应用: python setup.py py2app
5、生成的应用在dist目录下面
更多关于 py2app :http://undefined.org/python/py2app.html
如果想打包生成exe文件使用 py2exe :http://www.py2exe.org/index.cgi/Tutorial