2009-08-13 100 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

相关问题