質問

I'd need help trying to figure out this thing.
Yesterday I installed the beta of Spyder 2.3 to work with Anaconda Python 3.3, on my Win7 64-bit laptop. Opening an internal console window, I noticed an error that triggered every sec,

Traceback (most recent call last):
File "C:\Miniconda3\lib\site-packages\spyderlib\widgets\status.py", line 80, in update_label
  self.label.setText('%d %%' % self.get_value())
File "C:\Miniconda3\lib\site-packages\spyderlib\widgets\status.py", line 93, in get_value
  return memory_usage()
File "C:\Miniconda3\lib\site-packages\spyderlib\utils\system.py", line 20, in windows_memory_usage
  class MemoryStatus(wintypes.Structure):
AttributeError: 'module' object has no attribute 'Structure'

This appears to come from the fact that system.py tries to use "wintype.Structure" when psutil is not installed, and I can see no such thing as a Structure class (or module) in wintypes.py... Even c_uint64 is not in wintypes.

I solved the issue the easy way - I just installed psutil and was done. But the fact is that several scripts appear to use wintypes.Structure (see Google). And I really don't see it... so what am I missing?
Thanks!

役に立ちましたか?

解決

I'm editing my answer.

The problem here appears to be that the Python 2.7 version of wintypes.py (from the ctypes 1.1.0 package) starts with
from ctypes import *

while wintypes.py from the Python 3.3 ctypes 1.1.0 package uses:
import ctypes

So basically wintypes.Structure, .c_uint64, .sizeof and .byref are all from ctypes. They don't get altered in wintypes - at least not up to this 1.1.0 version. So this change to Spyder(2.3.0beta3)'s status.py should make it work with no errors both for Python 2.7 and Python 3.3:

def windows_memory_usage():
    """Return physical memory usage (float)
    Works on Windows platforms only"""
    from ctypes import windll, Structure, c_uint64, sizeof, byref
    from ctypes.wintypes import DWORD
    class MemoryStatus(Structure):
        _fields_ = [('dwLength', DWORD),
                    ('dwMemoryLoad',DWORD),
                    ('ullTotalPhys', c_uint64),
                    ('ullAvailPhys', c_uint64),
                    ('ullTotalPageFile', c_uint64),
                    ('ullAvailPageFile', c_uint64),
                    ('ullTotalVirtual', c_uint64),
                    ('ullAvailVirtual', c_uint64),
                    ('ullAvailExtendedVirtual', c_uint64),]
    memorystatus = MemoryStatus()
    # MSDN documetation states that dwLength must be set to MemoryStatus
    # size before calling GlobalMemoryStatusEx
    # http://msdn.microsoft.com/en-us/library/aa366770(v=vs.85)
    memorystatus.dwLength = sizeof(memorystatus)
    windll.kernel32.GlobalMemoryStatusEx(byref(memorystatus))
    return float(memorystatus.dwMemoryLoad)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top