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

OSX端口Python库路径?找不到ctypes,python,macos,path,Python,Macos,Path,我试图使用依赖于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 impor

我试图使用依赖于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
然后我尝试通过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’),这会带来什么麻烦吗

这方面有什么办法吗

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

ctypes
是自2.5版以来的标准Python库,因此不需要py-ctypes。在我的2.6.5安装中,获取导入错误的行仍然存在

我没有OSX,所以我的问题是:
/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5
属于Python 2.5的标准安装,还是可能属于某个框架的坏安装

在运行的python shell中,可以检查
sys.path
的值。可能在标准库之前有一些损坏的库


舍邦行
#/如果usr/bin/python
是像普通程序一样直接调用的可执行脚本的第一行,则操作系统将对其进行解释。在所有其他情况下,这只是一个评论。特别是,如果您在
python myscript.py中调用脚本,或者由其他python代码导入脚本,那么该行将被忽略。

一个简单的解决方案是使用Mac OS附带的本机python构建。这肯定适用于最新版本的MacOSX10.6.4,它包含Python2.6

下面是一个显示正在成功导入“\u 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']
>>> 
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
>>>
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']
>>>