带有psutil模块的Python py2app

时间:2012-03-14 00:09:44

标签: python macos py2app

我有一个Python应用程序我试图制作一个使用py2app的独立版本。但是,当我执行.app文件时,它会终止并出现以下错误

ImportError: No module named _psutil_osx

以下示例应用程序(test.py)具有相同的问题,但在运行python test.py时工作正常:

from psutil import cpu_percent
print cpu_percent()

然后我从终端

运行以下内容
py2applet --make-setup test.py
python setup.py py2app

以下是来自控制台的错误日志

[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]: Traceback (most recent call last):
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:   File "/Users/MyUser/Documents/Python/testpy/dist/test.app/Contents/Resources/__boot__.py", line 320, in <module>
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:     _run('test.py')
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:   File "/Users/MyUser/Documents/Python/testpy/dist/test.app/Contents/Resources/__boot__.py", line 317, in _run
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:     execfile(path, globals(), globals())
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:   File "/Users/MyUser/Documents/Python/testpy/dist/test.app/Contents/Resources/test.py", line 1, in <module>
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:     from psutil import cpu_percent
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:   File "build/bdist.macosx-10.7-intel/egg/psutil/__init__.py", line 77, in <module>
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]:   File "build/bdist.macosx-10.7-intel/egg/psutil/_psosx.py", line 14, in <module>
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]: ImportError: No module named _psutil_osx
test[34841]: test Error
[0x0-0xd80d8].org.pythonmac.unspecified.test[34841]: Exited with code: 255 

似乎导入psutil就好了但其中一个子包是_psutil_osx并且没有导入。知道为什么不包括在内吗?我已经尝试将其添加到我的包含,并在setup.py文件中也需要,但无济于事。提前致谢

1 个答案:

答案 0 :(得分:0)

_psutil_osx模块是一个已编译的共享库。您需要使用py2app的框架选项来包含它。 “