(OSX = 山狮)我在 /dist 中的应用程序抛出错误:
Last login: Wed Aug 28 11:21:29 on ttys001
-MacBook-Pro:~ $ /Users/Desktop/dist/abc.app/Contents/MacOS/abc ; exit;
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/py2app/apptemplate/lib/site.py", line 20, in <module>
import os
File "os.pyc", line 398, in <module>
File "UserDict.pyc", line 83, in <module>
File "_abcoll.pyc", line 11, in <module>
File "/Users/Virendra/Desktop/dist/abc.app/Contents/Resources/abc.py", line 6, in <module>
import psutil
File "build/bdist.macosx-10.8-x86_64/egg/psutil/__init__.py", line 54, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_common.py", line 16, in <module>
File "build/bdist.macosx-10.8-x86_64/egg/psutil/_compat.py", line 65, in <module>
File "collections.pyc", line 6, in <module>
AttributeError: 'module' object has no attribute '__all__'
logout
我的 setup.py (即使没有 - 'import os' 也会出现同样的错误)看起来像:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['abc.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True, 'includes': ['psutil', 'time', 'socket', 'os']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
还有有问题的脚本 abc.py:
from psutil import cpu_times_percent
import socket
import time
serverHost = "localhost"
thisClient = socket.gethostname()
cpuStats = psutil.cpu_times_percent()
print cpuStats
currentTime = int(time.time())
s = socket.socket()
s.connect((serverHost,8080))
command = 'put cpu.usr ' + str(currentTime) + " " + str(cpuStats[0]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.nice ' + str(currentTime) + " " + str(cpuStats[1]) +" host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.sys ' + str(currentTime) + " " + str(cpuStats[2]) + " host="+ thisClient+ "\n"
s.sendall(command)
command = 'put cpu.idle ' + str(currentTime) + " " + str(cpuStats[3]) + " host="+ thisClient+ "\n"
s.sendall(command)
s.close()
最初是“import psutil”,我将其更改为“from psutil ...”,如上所述。在此处包括“导入操作系统...”。但是所有组合都会引发相同的错误。在其他地方,我将“import psutil”视为标准导入,这也不例外。该错误还AttributeError: 'module' object has no attribute '__all__'
意味着什么?谢谢。