ctypes import 不适用于 python 2.5

发布于 2024-10-09 05:48:23 字数 1142 浏览 2 评论 0原文

我正在尝试导入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深海蓝天 2024-10-16 05:48:23

可能是文件权限问题。我没有方便的 MacPorts Python 2.5 安装,但基于 MacPorts Python 2.6,应该有一个类似这样的文件:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.5
$ cd ./lib/python2.5/lib-dynload/
$ ls -l _ctypes.so 
-rwxr-xr-x  2 root  wheel  151536 Oct  8 00:26 _ctypes.so*

如果没有,请使用 ls -l 的结果更新您的问题上面的 lib-dynload 目录。

更新:根据您的附加信息,_ctypes_failed.so 的存在表明 _ctypes 在 Python 2.5 的构建和安装过程中构建失败。尝试使用详细模式重新安装它,看看失败是什么:

$ port sudo selfupdate
$ port -v upgrade --force python25

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:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.5
$ cd ./lib/python2.5/lib-dynload/
$ ls -l _ctypes.so 
-rwxr-xr-x  2 root  wheel  151536 Oct  8 00:26 _ctypes.so*

If not, update your question with the results of an ls -l of the lib-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:

$ port sudo selfupdate
$ port -v upgrade --force python25
失而复得 2024-10-16 05:48:23

最新的 Mac OS X 附带了 Python 2.6。尝试使用它而不是 macports。导入 ctypes 已在我的系统上运行。

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>

The latest Mac OS X ships with Python 2.6. Try using that instead of macports. Importing ctypes works already on my system.

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>
各自安好 2024-10-16 05:48:23

安装 libffi,然后重建 Python。

Install libffi, then rebuild Python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文