我已经在带有 Apache2.4.7 的 Ubuntu 服务器上安装了我的 Django 应用程序,并将其配置为使用虚拟环境中的 py3.5.2。
但是,根据我在错误中看到的内容,它从 3.5 开始,默认为 3.4。
请解释为什么会这样:
/var/www/venv/lib/python3.5/site-packages
/usr/lib/python3.4
查看下面的完整错误:
SyntaxError at /
invalid syntax (forms.py, line 2)
Request Method: GET
Request URL: http://intranet.example.com/
Django Version: 1.10.1
Exception Type: SyntaxError
Exception Value:
invalid syntax (forms.py, line 2)
Exception Location: /var/www/intranet/formater/views.py in <module>, line 7
Python Executable: /usr/bin/python3
Python Version: 3.4.3
Python Path:
['/var/www/intranet',
'/var/www/venv/lib/python3.5/site-packages',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages',
'/var/www/intranet',
'/var/www/intranet/venv/lib/python3.5/site-packages']
这是我的 apache2.conf 文件:
WSGIScriptAlias / /var/www/intranet/intranet/wsgi.py
#WSGIPythonPath /var/www/intranet/:/var/www/intranet/venv/lib/python3.5/site-packages
WSGIDaemonProcess intranet.example.com python-path=/var/www/intranet:/var/www/venv/lib/python3.5/site-packages
WSGIProcessGroup intranet.example.com
<Directory /var/www/intranet/intranet>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
我在这里做错了什么?
最佳答案
Apache 的 mod_wsgi 模块是为特定的 Python 版本编译的。您不能通过将其指向不同 Python 版本的 Python 虚拟环境来使其使用不同的 Python 版本运行。这在 mod_wsgi 文档中提到了关于使用 Python 虚拟环境的清除:
如果 mod_wsgi 最初是为 Python 3.4 编译的,那么让它作为 Python 3.5 运行的唯一方法是卸载该版本的 mod_wsgi 并构建/安装为 Python 3.5 编译的 mod_wsgi 版本。
关于python - Django Apache wsgi 更改 python 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40946211/