0

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

askance
  • 1,077
  • 4
  • 14
  • 19

1 Answers1

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.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • Thx. It worked! But I am getting a new (albeit unrelated to the original issue) error as follows: [It lists the cpupercent at the top but goes on to detail the error - I am not following the output here - Any help/explanation is much appreciated ] $ ./dist/test1.app/Contents/MacOS/test1 cpupercent(user=2.4, nice=0.0, system=4.8, idle=92.9) Traceback (most recent call last): [includes only the last part] line 16, in s.connect((serverHost,4242)) File "socket.pyc", line 224, in meth socket.error: [Errno 61] Connection refused 2013-08-28 12:50:25.104 test1[4519:707] test1 Error – askance Aug 28 '13 at 19:53
  • Please don't ask new, unrelated questions in comments. They will likely be overlooked and any discussion won't include or benefit others. You should open a new question. That said, "connection refused" seems pretty clear. You need to make sure you can establish a connection to the server application, what ever it is, at the network address contained in `serverHost` at port 4242. But, again, open a new question if you are still having problems. – Ned Deily Aug 28 '13 at 20:31
  • Okay. Thx. Let me check with a different port and will update as advised. – askance Aug 28 '13 at 20:52