简体   繁体   English

为什么我不能在Python中安装pycrypto后导入Crypto?

[英]Why can't I import Crypto after installing pycrypto in Python?

On OSX 10.10, I'm getting 'ImportError: No module named Crypto' in Python 2.7.6 after installing the pycrypto module. 在OSX 10.10上,我在安装pycrypto模块后得到了Python 2.7.6中的'ImportError:没有名为Crypto的模块'。 I get the error when I run python in the terminal and try import Crypto . 当我在终端中运行python并尝试import Crypto时,我收到错误。

I've installed via sudo pip install pycrypto and also tried installing from source from here: https://pypi.python.org/pypi/pycrypto . 我已通过sudo pip install pycrypto安装,并尝试从此处安装源代码: httpssudo pip install pycrypto According to that site, there's a python setup.py test command (which runs fine for me), but it skips modules which aren't available, so I'm not sure if it's actually useful in this case. 根据该网站,有一个python setup.py test命令(对我运行正常),但它跳过不可用的模块,所以我不确定它在这种情况下是否真的有用。

The only thing I tried to do was find and compare to other packages in /Library/Python/2.7/site-packages ... I noticed that the other packages (like Naked, PyYAML, and others) have directories whereas pycrypto just has an 'ASCII text' file (and no directory) according to the file pycrypto-2.6.1-py2.7.egg-info command. 我唯一想做的就是找到并与/Library/Python/2.7/site-packages其他软件包进行比较......我注意到其他软件包(如Naked,PyYAML和其他软件包)都有目录,而pycrypto只有一个根据file pycrypto-2.6.1-py2.7.egg-info命令,'ASCII text'文件(没有目录)。 This scenario was after installing from source. 此方案是从源安装后。

When installing from pip , I see that 'pycrypto-2.6.1-py2.7.egg-info' shows up as a directory, but there aren't any .py files in there. pip安装时,我看到'pycrypto-2.6.1-py2.7.egg-info'显示为目录,但其中没有任何.py文件。

I'm new to python and really at a loss. 我是python的新手,真的很茫然。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

The issue was not related to the .egg files - it was the Crypto directory itself. 该问题与.egg文件无关 - 它是Crypto目录本身。

In my working solution I can't remember whether I used apt-get or whether I installed PyCrypto from source, but in the /Library/Python/2.7/site-packages directory I needed to rename the crypto directory to Crypto and everything worked fine. 在我的工作解决方案中,我不记得是否使用了apt-get或是否从源代码安装了PyCrypto,但是在/Library/Python/2.7/site-packages目录中我需要将crypto目录重命名为Crypto ,一切正常。

I had the same problem in CentOS-6. 我在CentOS-6中遇到了同样的问题。

But I tried yum install python-devel (install python dev didin't work) followed by easy_install pycrypto . 但我尝试了yum install python-devel (安装python开发没有工作),然后是easy_install pycrypto Now you can import and use without any problem 现在您可以毫无问题地导入和使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM