我在virtualenv中安装了py-bcrypt,但是当应用程序通过WSGI运行时,我无法在virtualenv中加载库。
python /var/www/api-test/api.wsgi
Traceback (most recent call last):
File "/var/www/api-test/api.wsgi", line 3, in <module>
from api import app as application
File "/var/www/api-test/api.py", line 5, in <module>
import os, hashlib, bcrypt
ImportError: No module named bcrypt
然而,运行python并手动加载库可以正常工作
python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bcrypt
>>> bcrypt
<module 'bcrypt' from '/var/www/api-test/api-env/local/lib/python2.7/site-packages/bcrypt/__init__.pyc'>
>>>
答案 0 :(得分:0)
原来我需要将以下内容添加到我的api.wsgi文件中:
import site
site.addsitedir("/var/www/api-test/api-env/lib/python2.7/site-packages")