【问题标题】:python3 virtualenv no such file or directorypython3 virtualenv没有这样的文件或目录
【发布时间】:2015-03-08 09:32:25
【问题描述】:

我正在尝试按照本指南 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'

请帮我解决这个问题,我感觉很亲密!

【问题讨论】:

    标签: python django python-3.x


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,解决了这个问题。但现在看来它使用的是 python 2.7 而不是 3.2。进一步进入兔子洞我去......
    • 确实如此。实际上你应该强制 WSGI 服务器使用/home/whatever/chris/.virtualenvs/splinter/bin/python 作为the解释器。
    • 我在哪里设置呢?请参阅我与此相关的其他问题stackoverflow.com/questions/28926170/…
    • 你的操作系统是什么。 mod_wsgi 必须为您的确切 python 版本构建...
    • Ubuntu。我从源代码安装了 mod_wsgi,但我不确定它是否被使用而不是我安装的原始版本。我对这一切都很陌生,我相信你能说出来......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-11
    • 2018-09-17
    • 2020-04-30
    • 2020-06-28
    • 1970-01-01
    • 2021-06-24
    相关资源
    最近更新 更多