2014-01-14 50 views
3

試圖安裝和使用pycrypto。我在安裝過程中沒有收到任何錯誤,所以我無法進一步排除故障。PyCrypto在OSX小牛中不工作

我跑'測試',並出現以下錯誤,但無法找到它的修復。

僅供參考,我已經安裝了XCode和Commandline工具。

mac:pycrypto-2.6.1 rajivvishwa$ export ARCHFLAGS='-arch i386 -arch x86_64' 
mac:pycrypto-2.6.1 rajivvishwa$ sudo python setup.py build 
running build 
running build_py 
running build_ext 
running build_configure 
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. 
mac:pycrypto-2.6.1 rajivvishwa$ sudo python setup.py install 
running install 
running build 
running build_py 
running build_ext 
running build_configure 
warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath. 
running install_lib 
running install_egg_info 
Removing /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pycrypto-2.6.1-py2.6.egg-info 
Writing /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pycrypto-2.6.1-py2.6.egg-info 

mac:pycrypto-2.6.1 rajivvishwa$ sudo python setup.py test 
running test 
.......................................................................................................................................................................................................... SelfTest: You can ignore the RandomPool_DeprecationWarning that follows. 
build/lib.macosx-10.9-intel-2.6/Crypto/Util/randpool.py:40: RandomPool_DeprecationWarning: This application uses RandomPool, which is BROKEN in older releases. See http://www.pycrypto.org/randpool-broken 
    RandomPool_DeprecationWarning) 
..........E................... 
====================================================================== 
ERROR: Test that mpzToLongObj and longObjToMPZ (internal functions) roundtrip negative numbers correctly. 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "build/lib.macosx-10.9-intel-2.6/Crypto/SelfTest/Util/test_number.py", line 283, in test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ 
    k = number._fastmath.rsa_construct(n, e) 
AttributeError: 'NoneType' object has no attribute 'rsa_construct' 

---------------------------------------------------------------------- 
Ran 1033 tests in 150.196s 

FAILED (errors=1) 
Traceback (most recent call last): 
    File "setup.py", line 456, in <module> 
    core.setup(**kw) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 152, in setup 
    dist.run_commands() 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands 
    self.run_command(cmd) 
    File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 995, in run_command 
    cmd_obj.run() 
    File "setup.py", line 336, in run 
    SelfTest.run(module=moduleObj, verbosity=self.verbose, stream=sys.stdout, config=self.config) 
    File "build/lib.macosx-10.9-intel-2.6/Crypto/SelfTest/__init__.py", line 74, in run 
    raise SelfTestError("Self-test failed", result) 
Crypto.SelfTest.SelfTestError: ('Self-test failed', <unittest._TextTestResult run=1033 errors=1 failures=0>) 

mac:pycrypto-2.6.1 rajivvishwa$ python 
Python 2.6.8 (unknown, Aug 25 2013, 00:04:29) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import Crypto 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named Crypto 

回答

3

如果您通過MacPorts的蟒蛇,嘗試

sudo port install py27-crypto 

然後導入加密應該工作

+0

我試過了,它看起來像pycrypto現在安裝在python2.7,而不是我的默認python。我可以使用macports安裝默認的python嗎? – rajivvishwa

+0

不,你不能使用macports,macports是替代python,對於默認python,你應該嘗試brew安裝 – bistaumanga

+0

由於mavericks更新,brew對我來說是破碎的。 http://stackoverflow.com/questions/19635804。 – rajivvishwa

2

如果你要安裝最新的OSX pycrypto然後設置「鐺」的C編譯器配置將使用。這是通過CC環境變量完成的。

的方式在virtualenv中調試這樣的:

sudo easy_install virtualenv==1.10.1 
virtualenv venv 
export CC=clang 
venv/bin/pip install --no-clean pycrypto 
cat venv/build/pycrypto/config.log 
0

這看起來像在Mac文件系統的情況下,不敏感的偏好。 Linux區分大小寫,我的猜測是軟件包所有者使用Linux來創建軟件包。

我首先安裝了加密包(作爲最後的手段使用sudo)。

sudo pip install pycrypto 

pip install crypto 

然後,只需將小寫包名重命名爲大寫。

/path/to/venv/lib/python2.7/site-packages中,將crypto重命名爲Crypto