2010-10-12 7 views
1

Je suis en train d'utiliser une application qui a une dépendance de ctypes, mais je reçois cette erreur:Chemin de la bibliothèque OSX Port Python? Je ne trouve pas 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 

J'ai installé PY-ctypes de ports, mais il semble être seulement Python 2.4 Version:

$ 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 

J'ai ensuite essayé de lancer l'application via python2.4, mais il semble que l'application utilise la syntaxe qui est disponible uniquement dans 2,5:

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

Mon python installation est également de ports OSX, et je remarquai dans l'application Peach, elle définit python comme:

#!/usr/bin/python 

Est-ce que ce désordre avec quoi que ce soit si mes points exécutables python par défaut à mon installation portuaire (et je suis en cours d'exécution 'python peach.py')?

$ which python 
/opt/local/bin/python 

Y a-t-il des solutions pour cela?

  • ctypes pour python2.5?
  • Possibilité d'ajouter 2,4 bibliothèques à 2,5 chemin?

Répondre

2

Une solution simple consisterait à utiliser la version native de Python fournie avec Mac OS. Cela fonctionne définitivement avec la dernière version de Mac OS X 10.6.4, qui a Python 2.6.

Voici un exemple montrant que « _ctypes » est importé avec succès:

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 
>>> 

Si vous avez des problèmes après cela, essayez de regarder l'attribut sys.path pour voir quels modules et versions sont dans votre chemin .

Voici un exemple de visualiser le contenu de sys.path sur un nouveau Mac OS 10.6.4 build:

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'] 
>>> 
1

est une bibliothèque Python standard depuis la version 2.5, donc py-ctypes n'est pas nécessaire. La ligne à laquelle vous obtenez une ImportError existe toujours dans mon installation 2.6.5.

Je ne possède pas OSX, donc ma question est la suivante: est-ce que /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5 appartient à l'installation standard de Python 2.5, ou est-ce que cela peut faire partie d'une installation éventuellement cassée d'un framework?

Dans un shell Python en cours d'exécution, vous pouviez inspecter la valeur sys.path. Peut-être qu'il y a une bibliothèque cassée qui précède la bibliothèque standard.

La ligne shebang #!/usr/bin/python est interprétée par le système d'exploitation s'il s'agit de la première ligne d'un script exécutable qui est appelée directement comme un programme ordinaire. Dans tous les autres cas, c'est juste un commentaire. En particulier, la ligne est ignorée si vous appelez le script comme dans python myscript.py ou s'il est importé par un autre code Python.

Questions connexes