我使用Python 3.2在Mac OSX Lion上编译并安装了pycrypto 2.6,但是当我尝试运行命令时
import Crypto.Cipher.AES
我遇到了这个问题
Traceback (most recent call last):
File "/Users/DaZzz/Documents/Python Workspace/Cryptography Coursera/W2PA.py", line 8, in <module>
import Crypto.Cipher.AES
File "/Library/Python/2.7/site-packages/Crypto/Cipher/AES.py", line 50, in <module>
from Crypto.Cipher import _AES
ImportError: dlopen(/Library/Python/2.7/site-packages/Crypto/Cipher/_AES.so, 2): Symbol not found: _PyInt_FromLong
Referenced from: /Library/Python/2.7/site-packages/Crypto/Cipher/_AES.so
Expected in: flat namespace
in /Library/Python/2.7/site-packages/Crypto/Cipher/_AES.so
顺便说一句,我使用安装了PyDev的eclipse。我也尝试在IDLE中运行它,但是我得到了以下错误:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import Crypto.Cipher.AES
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/Crypto/Cipher/AES.py", line 50, in <module>
from Crypto.Cipher import _AES
ImportError: cannot import name _AES
应该强调的是,要在IDLE中运行它,我将使用Crypto的目录复制到python路径中。
我做错了什么?
答案 0 :(得分:0)
请参阅消息中的/Library/Python/2.7
?看来你实际上在这里运行Python 2.7。你需要告诉PyDev使用Python 3.2。你确定你使用了IDLE的Python 3.2版本吗?每个版本的Python都有单独的IDLE。尝试从命令行键入idle3.2
,或在Finder中单击/Applications/Python 3.2/IDLE.app
。
更新:使用python.org 64/32位Python 3.2.3和Xcode 4.3为我工作(你可能需要为/Developer
创建一个符号链接来解决Xcode SDK位置的变化4.3)。
# for Xcode 4.3+ only
$ [ ! -e /Developer ] && sudo ln -s Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /Developer
$ tar xf ./pycrypto-2.6.tar.gz
$ cd ./pycrypto-2.6
$ python3.2 setup.py install
$ cd
$ python3.2
Python 3.2.3 (v3.2.3:3d0686d90f55, Apr 10 2012, 11:25:50)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Crypto.Cipher.AES
>>> Crypto.Cipher.AES.__file__
'/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages/Crypto/Cipher/AES.py'