Tim*_*ard 7 python mod-wsgi virtualenv flask
我很擅长使用Flask-
根据http://flask.pocoo.org/docs/0.12/deploying/mod_wsgi/
在"使用虚拟环境"标题下,我读到:
对于Python 3,将以下行添加到.wsgi文件的顶部:
Run Code Online (Sandbox Code Playgroud)activate_this = '/path/to/env/bin/activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) This sets up the load paths according to the settings of the virtual environment.请记住,路径必须是绝对的.
激活我的venv我使用linux的命令:
my_env/bin/activate
Run Code Online (Sandbox Code Playgroud)
我查看了my_env/bin /目录,但没有看到任何.py文件.我想在my_env/bin /中创建一个.py文件,该文件将被.wsgi文件调用吗?
Aar*_*ndt 10
我遇到了同样的问题,解决方案实际上很简单。您需要安装libapache2-mod-wsgi-py3而不是libapache2-mod-wsgi. 后者适用于 python 2。
然后,您可以通过将环境的站点包添加到系统路径来激活您的环境。例如,对我来说(使用 venv),我可以通过将以下行添加到我的*.wgsi文件中来做到这一点。
sys.path.insert(0,"/path/to/venv/lib/python3.8/site-packages")
Run Code Online (Sandbox Code Playgroud)
如果您使用 mod_wsgi,请阅读以下文档:
总而言之:
From Documentation - to use a Python virtual environment, all you need to do is add the python-home option to the WSGIDaemonProcess directive resulting in
将此行添加到您的虚拟主机以启用 virtualenv
WSGIDaemonProcess application_name python-home=/path/to/app/venv