【发布时间】:2010-12-26 22:48:36
【问题描述】:
我正在尝试导入 ctypes,并且我正在使用通过 macports 安装的 Python 2.5.5(在 Mac OS X 10.6 上)。
我收到一条错误消息“ImportError:没有名为 _ctypes 的模块”(请参阅下面的详细信息)。据我了解,ctypes 应该是为 python 2.5 预装的。有什么建议吗?
谢谢, 索拉布
错误详情:
$ python
Python 2.5.5 (r255:77872, Nov 30 2010, 00:05:47)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/\_\_init\_\_.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
更新:我检查了 /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload 目录,没有 Ned 的回复。没有 _ctypes.so 文件,但是有两个相关文件:
-rwxr-xr-x 2 root wheel 136176 Nov 30 00:07 _ctypes_failed.so
-rwxr-xr-x 2 root wheel 26160 Nov 30 00:05 _ctypes_test.so
这是否意味着我需要重新安装 ctypes?
更新 2:重新安装 python 2.5 解决了这个问题。不太确定是什么导致了原始问题。
【问题讨论】:
-
哇,我不知道人们还在使用 2.5。
-
@Rook 的人仍然使用 Python 2.4.x。
-
@Rook 在 Red hat、CentOS 和其他一些服务器发行版上,拥有 2.5 甚至 2.4 仍然很常见。 Google 不使用任何超过 2.5 的版本(事实上,要开发 App Engine,您必须以 2.5 为目标)。
-
它可能与路径变量有关。 this post 的解决方案是删除
APPDATA环境变量。也许这可以解决您的问题? -
@marcog 我没有任何名为 APPDATA 的环境变量。 @Rook 由于某些依赖关系,我需要 python2.5。导入 ctypes 实际上在我的 python2.6 系统上运行良好。
标签: python macos ctypes python-2.5