2009-08-13 54 views
4
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on 
win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import ctypes 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Python26\lib\ctypes\__init__.py", line 17, in <module> 
    from struct import calcsize as _calcsize 
ImportError: cannot import name calcsize 

>>> from ctypes import * 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "C:\Python26\lib\ctypes\__init__.py", line 17, in <module> 
    from struct import calcsize as _calcsize 
ImportError: cannot import name calcsize 
>>> 

回答

8

看來你的路徑中有另一個struct.py。

試試這個,看看蟒蛇找到你的結構模塊:

>>> import inspect 
>>> import struct 
>>> inspect.getabsfile(struct) 
'c:\\python26\\lib\\struct.py' 
+0

小學生的錯誤。運行cmd.exe會將CWD默認爲桌面。我曾經問過一個問題的臨時腳本(http://stackoverflow.com/questions/1264833/python-class-factory-to-produce-simple-struct-like-classes)。儘管如此,我會記得檢查。謝謝。 – kjfletch 2009-08-13 08:28:21

+0

在你的軟件包層次結構中,你不應該有兩個同名的軟件包。我無法定義一個「結構」包,並與NumPy發生了一些有趣的衝突。人們可能會認爲這不應該是一個問題,但它確實是一個問題。即使使用Python 3。 – 2016-09-07 15:37:12

相關問題