【问题标题】:Why does import of ctypes raise ImportError?为什么导入 ctypes 会引发 ImportError?
【发布时间】:2009-08-13 08:18:24
【问题描述】:
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
>>>

【问题讨论】:

标签: python ctypes python-2.6 importerror


【解决方案1】:

您的路径中似乎还有另一个 struct.py。

试试这个看看python在哪里找到你的结构模块:

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

【讨论】:

  • 小学生错误。运行 cmd.exe 将 CWD 默认设置为桌面。我之前问过的一个问题(stackoverflow.com/questions/1264833/…)有一个临时脚本。我会记得检查。谢谢。
  • 你的包层次结构中不能有两个同名的包。我很鲁莽地定义了一个“结构”包,并与 NumPy 发生了一些有趣的冲突。不应该真的是一个问题,一个人可能会想,但它确实是。即使使用 Python 3。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-22
  • 2021-11-10
  • 2021-12-24
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
相关资源
最近更新 更多