ctypes import 不适用于 python 2.5
我正在尝试导入 ctypes,并且使用的是通过 macports 安装的 Python 2.5.5(在 Mac OS X 10.6 上)。
我收到一条错误消息“ImportError:没有名为 _ctypes 的模块”(请参阅下面的详细信息)。据我了解,ctypes 应该是为 python 2.5 预安装的。有什么建议吗?
谢谢, Saurabh
错误详细信息:
$ 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 解决了问题。不太确定是什么导致了最初的问题。
I am trying to import ctypes, and I am using Python 2.5.5 installed using macports (on Mac OS X 10.6).
I get an error saying "ImportError: No module named _ctypes" (see details below). As I understand it ctypes is supposed to come preinstalled for python 2.5. Any suggestions?
thanks,
Saurabh
Error details:
$ 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
Update: I checked the /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload
directory based no Ned's reply. There is no _ctypes.so file, however the two related files that are there are:
-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
Does this mean I need to reinstall ctypes?
Update 2: Reinstalling python 2.5 solved the problem. Not quite sure what caused the original problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能是文件权限问题。我没有方便的 MacPorts Python 2.5 安装,但基于 MacPorts Python 2.6,应该有一个类似这样的文件:
如果没有,请使用
ls -l
的结果更新您的问题上面的lib-dynload
目录。更新:根据您的附加信息,
_ctypes_failed.so
的存在表明_ctypes
在 Python 2.5 的构建和安装过程中构建失败。尝试使用详细模式重新安装它,看看失败是什么:It might be a file permission problem. I don't have a MacPorts Python 2.5 installation handy but, based on a MacPorts Python 2.6, there should be a file something like this:
If not, update your question with the results of an
ls -l
of thelib-dynload
directory above.Update: based on your additional information, the presence of
_ctypes_failed.so
indicates that the building of_ctypes
failed during the build and installation of Python 2.5. Try reinstalling it with verbose mode to see what the failure is:最新的 Mac OS X 附带了 Python 2.6。尝试使用它而不是 macports。导入 ctypes 已在我的系统上运行。
The latest Mac OS X ships with Python 2.6. Try using that instead of macports. Importing ctypes works already on my system.
安装 libffi,然后重建 Python。
Install libffi, then rebuild Python.