Virtualenv PyCrypto无法导入加密模块

时间:2013-03-05 10:08:14

标签: django cryptography virtualenv pip pycrypto

Python,Django 1.3.5
我正在使用virtualenv,sudo pip安装PyCrypto == 2.6,这是成功的。
但是Django的错误:

Traceback (most recent call last):
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 169, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/zhanglei/Develop/medweb-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/zhanglei/Develop/medweb/urls.py", line 9, in <module>
from website.views import index, home, login, register, read_verify_code, clinic_problems, \
File "/Users/zhanglei/Develop/medweb/website/views.py", line 13, in <module>
from api.views import alipay_data_process
File "/Users/zhanglei/Develop/medweb/api/views.py", line 26, in <module>
from api.alipay import check_with_rsa_ali, parse_notify_data, decrypt_with_rsa_chunyu
File "/Users/zhanglei/Develop/medweb/api/alipay/__init__.py", line 2, in <module>
from Crypto import Signature
ImportError: No module named Crypto

但是当我在本地环境中安装pycrypto时,它可以通过python导入。

1 个答案:

答案 0 :(得分:1)

当您使用sudo时,它以root身份运行并安装在系统目录中。当你进入virtualenv时,你想以普通用户的身份运行它:

source medweb-env/bin/activate
pip install pycrypto==2.6