gpt4 book ai didi

python - OSX 端口 Python 库路径?找不到ctypes

转载 作者:行者123 更新时间:2023-11-30 23:57:03 26 4
gpt4 key购买 nike

我正在尝试使用依赖于 ctypes 的应用程序,但收到此错误:

$ python peach.py -t ~/Desktop/fuzz/wav/template.xml 

] Peach 2.3.6 Runtime
] Copyright (c) Michael Eddington

Traceback (most recent call last):
File "peach.py", line 335, in <module>
from Peach.Engine import *
File "/opt/Peach-2.3.6/Peach/__init__.py", line 40, in <module>
import Publishers, Transformers
File "/opt/Peach-2.3.6/Peach/Publishers/__init__.py", line 37, in <module>
import file, sql, stdout, tcp, udp, com, process, http, icmp, raw, remote, dll, smtp
File "/opt/Peach-2.3.6/Peach/Publishers/file.py", line 37, in <module>
from Peach.Engine.engine import Engine
File "/opt/Peach-2.3.6/Peach/Engine/engine.py", line 835, in <module>
from Peach.Engine.state import StateEngine
File "/opt/Peach-2.3.6/Peach/Engine/state.py", line 38, in <module>
import sys, re, types, time, struct, ctypes
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

我已经从 ports 安装了 py-ctypes,但它似乎只是 Python 2.4 版本:

$ port contents py-ctypes
Port py-ctypes contains:
/opt/local/lib/python2.4/site-packages/_ctypes.so
/opt/local/lib/python2.4/site-packages/_ctypes_test.so
/opt/local/lib/python2.4/site-packages/ctypes/__init__.py
/opt/local/lib/python2.4/site-packages/ctypes/__init__.pyc
/opt/local/lib/python2.4/site-packages/ctypes/_endian.py
/opt/local/lib/python2.4/site-packages/ctypes/_endian.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/__init__.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/__init__.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dyld.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dyld.pyc
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dylib.py
/opt/local/lib/python2.4/site-packages/ctypes/macholib/dylib.pyc

然后我尝试通过 python2.4 运行该应用程序,但该应用程序似乎使用了仅在 2.5 中可用的语法:

$ python2.4 peach.py -t ~/Desktop/fuzz/wav/template.xml 
File "peach.py", line 498
finally:
^
SyntaxError: invalid syntax

我的 python 安装也是来自 OSX 端口,我注意到在 Peach 应用程序中,它将 python 定义为:

#!/usr/bin/python

如果我的默认 python 可执行文件指向我的端口安装(并且我正在运行“python peach.py​​”),这会造成任何困惑吗?

$ which python
/opt/local/bin/python

有什么办法可以解决这个问题吗?

    python2.5 的 ctypes?
  • 能够将 2.4 库添加到 2.5 路径吗?

最佳答案

一个简单的解决方案是使用 Mac OS 附带的 native Python 构建。这绝对适用于最新版本的 Mac OS X 10.6.4,其中包含 Python 2.6。

以下示例显示“_ctypes”已成功导入:

mariah:~ joet3ch$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from _ctypes import Union, Structure, Array
>>>

如果此后遇到问题,请尝试查看 sys.path 属性以查看路径中包含哪些模块和版本。

以下是在新的 Mac OS 10.6.4 版本上查看 sys.path 内容的示例:

mariah:~ joet3ch$ /usr/bin/python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Python/2.6/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode']
>>>

关于python - OSX 端口 Python 库路径?找不到ctypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3917391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com