python3 virtualenv没有这样的文件或目录

时间:2015-03-08 09:32:25

标签: python django python-3.x

我正在尝试按照本指南http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/在apache上设置虚拟环境。我在index.wsgi的最后阶段遇到了问题。这是我的index.wsgi的内容:

import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/splinter/lib/python3.2/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('/var/www/splinter')
sys.path.append('/var/www/splinter/splinter')

os.environ['DJANGO_SETTINGS_MODULE'] = 'splinter.settings'

# Activate your virtual env
activate_env=os.path.expanduser("~/.virtualenvs/splinter/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

错误日志说明:

No such file or directory: '/var/www/.virtualenvs/splinter/bin/activate_this.py'

它将'var / www /'添加到路径的前面,所以我尝试删除os.path.expanduser,即使现在路径正确,并且文件肯定存在,我仍然得到相同的错误:

No such file or directory: '~/.virtualenvs/splinter/bin/activate_this.py'

请帮我解决这个问题,我感觉非常接近!

1 个答案:

答案 0 :(得分:0)

另一种可能性是使用您的用户名来扩展用户名:

activate_env = os.path.expanduser(
    "~chris/.virtualenvs/splinter/bin/activate_this.py")