Error in py2app application

假装没事ソ 提交于 2020-01-07 07:54:05

问题


(OSX = Mountain lion) My app in /dist throws the error:

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

My setup.py (same error even without the - 'import os') looks like:

"""
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'],
)

And the scrip abc.py in question:

    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()

Initially it was 'import psutil' which I changed to the 'from psutil...' as above. Included the 'import os...' here. But all combinations throw the same error. Elsewhere, I have seen 'import psutil' as a standard import and this is no different. What else could the error AttributeError: 'module' object has no attribute '__all__' mean? Thx.


回答1:


Your script file, abc.py, conflicts with the Python standard library Abstract Base Class module, abc. The simplest solution should be to just change the name of your file to something else.



来源:https://stackoverflow.com/questions/18495949/error-in-py2app-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!