我有一个等待用户输入然后打印输入字符串的python脚本。假设此脚本名为“run.py”。
脚本run.py导入我写的其他一些python脚本,文件夹结构是:
+ py_app
- run.py
+ util
- __init__.py
- a.py
- b.py
- c.py
现在我希望我可以将这个小应用程序包装在.app文件中,以便其他mac用户只需双击即可运行该脚本。
我使用py2applet来完成这项工作:
py2applet --make-setup run.py
setup.py:
来自setuptools导入设置
APP = ['run.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
packages=['util']
然后
python setup.py py2app -A
running py2app
running build_py
creating build
creating build/bdist.macosx-10.11-intel
creating build/bdist.macosx-10.11-intel/lib
creating build/bdist.macosx-10.11-intel/lib/leancloud_util
copying util/__init__.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/a.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/b.py -> build/bdist.macosx-10.11-intel/lib/util
copying util/c.py -> build/bdist.macosx-10.11-intel/lib/util
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/collect
creating path/to/app/build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/temp
creating path/to/app/dist
creating build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/lib-dynload
creating build/bdist.macosx-10.11-intel/python2.7-semi_standalone/app/Frameworks
*** creating application bundle: run ***
Done!
一切似乎工作正常但是当我点击生成的应用程序时,终端没有出现......
我改变了run.py,使其变得非常简单:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from util.a import a
from util.b import b
from util.c import c
if __name__ == "__main__":
print '111111 ...'
但是,当我点击应用程序时没有任何反应,当然我在终端中调用它时脚本运行正常:
python run.py
我不确定可能是什么问题。任何建议将不胜感激,谢谢:)
答案 0 :(得分:0)
如果您的脚本包含系统调用,请注意,一旦打包,应用程序将丢失系统PATH,因此无法在PATH中找到脚本。
我的建议是在程序的最开头添加此代码:
os.environ["PATH"] += "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"