Python PyCrypto在OSX Mavericks中不起作用

Python PyCrypto在OSX Mavericks中不起作用,python,macos,osx-mavericks,pycrypto,Python,Macos,Osx Mavericks,Pycrypto,正在尝试安装和使用pycrypto。我在安装过程中没有遇到任何错误,因此无法进一步排除故障 我运行了“测试”并跟踪错误,但找不到修复程序 仅供参考,我已经安装了XCode和命令行工具 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 bu

正在尝试安装和使用pycrypto。我在安装过程中没有遇到任何错误,因此无法进一步排除故障

我运行了“测试”并跟踪错误,但找不到修复程序

仅供参考,我已经安装了XCode和命令行工具

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
mac:pycrypto-2.6.1 rajivvishwa$export-ARCHFLAGS='-arch i386-arch x86_64'
mac:pycrypto-2.6.1 rajivvishwa$sudo python setup.py build
运行构建
运行build\u py
运行build_ext
运行build\u configure
警告:未找到GMP或MPIR库;不建立加密公钥。
mac:pycrypto-2.6.1 rajivvishwa$sudo python setup.py安装
正在运行的安装
运行构建
运行build\u py
运行build_ext
运行build\u configure
警告:未找到GMP或MPIR库;不建立加密公钥。
正在运行安装库
正在运行安装\u鸡蛋\u信息
删除/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pycrypto-2.6.1-py2.6.egg-info
编写/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测试
运行试验
.......................................................................................................................................................................................................... 自检:您可以忽略下面的RandomPool_弃用警告。
build/lib.macosx-10.9-intel-2.6/Crypto/Util/randpool.py:40:RandomPool\u DeprecationWarning:此应用程序使用RandomPool,这在旧版本中被破坏。看见http://www.pycrypto.org/randpool-broken
随机池(不推荐警告)
E
======================================================================
错误:测试mpzToLongObj和longObjToMPZ(内部函数)是否正确返回负数。
----------------------------------------------------------------------
回溯(最近一次呼叫最后一次):
文件“build/lib.macosx-10.9-intel-2.6/Crypto/SelfTest/Util/test_number.py”,第283行,在test_negative_number_roundtrip_mpzToLongObj_longObjToMPZ中
k=数字。_fastmath.rsa_构造(n,e)
AttributeError:“非类型”对象没有属性“rsa\u构造”
----------------------------------------------------------------------
在150.196秒内进行了1033次测试
失败(错误=1)
回溯(最近一次呼叫最后一次):
文件“setup.py”,第456行,在
堆芯设置(**kw)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py”,第152行,在安装程序中
dist.run_命令()
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py”,第975行,在run_命令中
self.run_命令(cmd)
文件“/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py”,第995行,在run_命令中
cmd_obj.run()
运行中第336行的文件“setup.py”
SelfTest.run(module=moduleObj,verbosity=self.verbose,stream=sys.stdout,config=self.config)
文件“build/lib.macosx-10.9-intel-2.6/Crypto/SelfTest/__init__.py”,第74行,正在运行
引发自检错误(“自检失败”,结果)
Crypto.SelfTest.SelfTester错误:('Self-test failed',)
mac:pycrypto-2.6.1 rajivvishwa$python
Python 2.6.8(未知,2013年8月25日,00:04:29)
[GCC 4.2.1达尔文兼容苹果LLVM 5.0(clang-500.0.68)]
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入加密
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为Crypto的模块

如果您通过macports运行python,请尝试

sudo port install py27-crypto

然后导入加密应该可以工作

如果您想在最新的OSX上安装pycrypto,那么将'clang'设置为configure将使用的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

这看起来像是Mac文件系统中不区分大小写的首选项。Linux是区分大小写的,我猜包的所有者使用Linux来创建包

我首先安装了加密软件包(作为最后手段使用
sudo

然后将小写的包名重命名为大写


/path/to/venv/lib/python2.7/site packages
中,将
crypto
重命名为
crypto

我尝试了这个方法,看起来pycrypto现在安装在python2.7中,而不是在我的默认python中。我可以使用macports在默认python中安装吗?不,您不能使用macports,macports是用于替代python的,对于默认python,您应该尝试brew installbrew。由于mavericks更新,brew对我来说已损坏。
sudo pip install pycrypto

pip install crypto