IOError: [errno 2] 没有这样的文件或目录: '/var/www/.virtualenvs/exampleenv/bin/activate_this.py")



我使用virtualenv在vps上部署django应用程序。以下是 wsgi 文件放置在/var/www/example.wsgi 中的内容

import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/exampleenv/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/example')
sys.path.append('/var/www/example/example')
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
# Activate your virtual env
activate_env=os.path.expanduser("~/virtualenvs/exampleenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

但是错误.log文件显示以下错误。

IOError: [Errno 2] No such file or directory: '/var/www/.virtualenvs/exampleenv/bin/activate_this.py")

它正在/var/www 中寻找 virtualenv 而不是 ~/.virtualenv/.....

我已经检查了存在于~/.virtualenvs/exampleenv中的示例env的路径

该应用程序可能以不同的用户身份运行(哪个家庭目录是/var/www/),因此expanduser函数将使用其主页目录而不是您的。

将其他用户的文件放在您的主目录中不是一个好的做法。 尝试将虚拟环境放入 让我们说/var/www/<your_app>/.venv/var/www/.<your_app>_venv.

最新更新