Python 试图理解一个错误-wintypes.Structure
我需要帮助才能弄明白这件事。Python 试图理解一个错误-wintypes.Structure,python,spyder,Python,Spyder,我需要帮助才能弄明白这件事。 昨天,我在我的Win7 64位笔记本电脑上安装了Spyder 2.3的测试版,以与Anaconda Python 3.3配合使用。 打开一个内部控制台窗口,我注意到每秒都会触发一个错误 Traceback (most recent call last): File "C:\Miniconda3\lib\site-packages\spyderlib\widgets\status.py", line 80, in update_label self.label.s
昨天,我在我的Win7 64位笔记本电脑上安装了Spyder 2.3的测试版,以与Anaconda Python 3.3配合使用。 打开一个内部控制台窗口,我注意到每秒都会触发一个错误
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'
这似乎是因为在未安装psutil
时尝试使用“wintype.Structure
”,而我在中看不到结构类(或模块)之类的东西。。。甚至c_uint64
也不在wintypes
中
我用简单的方法解决了这个问题——我刚刚安装了psutil
,就完成了。但事实上,有几个脚本似乎使用了wintypes.Structure
(请参阅)。我真的不明白。。。那么我错过了什么呢?谢谢 我正在编辑我的答案 这里的问题似乎是Python 2.7版本的wintypes.py(来自ctypes 1.1.0包)以
从ctypes导入*
Python 3.3 ctypes 1.1.0包中的wintypes.py使用:导入ctypes
因此基本上wintypes.Structure
、.c_uint64
、.sizeof
和.byref
都来自ctypes
。它们在wintypes
中不会被更改-至少在1.1.0版本之前不会被更改。因此,对Spyder(2.3.0beta3)的status.py
的这一更改应该使它在Python 2.7和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)
尝试:从wintypes导入结构即使我将cwd设置为
ctypes
,这样我就可以直接从wintypes导入结构,我得到:ImportError:无法导入名称结构
名称“结构”未定义
即使这样导入:从ctypes导入wintypes?或者从ctypes.wintypes导入结构?哦,但是有一个wintypes.ctypes.Structure
!