在具有Python 3.6,Apache 2.4和Django 1.11的Ubuntu上安装mod_wsgi [英] Install mod_wsgi on Ubuntu with Python 3.6, Apache 2.4, and Django 1.11

查看:61
本文介绍了在具有Python 3.6,Apache 2.4和Django 1.11的Ubuntu上安装mod_wsgi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取针对Python 3.6.1编译的Apache2的mod_wsgi?

(或将来的任何Python版本)

(or any future Python version)

我正在将Python 3.6.1虚拟环境与Django 1.11配合使用,并且一切都根据Apache错误日志运行,但Apache 2.4的mod_wsgi已针对Python/3.5.1 +进行了编译,并且正在使用Python/3.5.2,因此我的Python 3.6.1代码失败,因为我使用的是3.5.2中不可用的新功能

I am using a Python 3.6.1 virtual environment with Django 1.11 and Everything is working according to the Apache error log except that mod_wsgi for Apache 2.4 was compiled for Python/3.5.1+ and is using Python/3.5.2 so my Python 3.6.1 code is failing because I'm using new features not available in 3.5.2

设置mod_wsgi似乎并没有使用我的Python 3.6.1虚拟环境(尽管它正在尝试使用它),但与设置我的系统有关的所有其他配置和安装似乎都很好(以守护程序模式运行)对于Django,根据错误日志)...

All of the other configurations and installs involved in setting my system up seem to be fine (Running in daemon mode) though mod_wsgi doesn't seem to be using my Python 3.6.1 virtual environment (though it is trying to use it for Django according to the error log)...

我曾经使用过: sudo apt-get install libapache2-mod-wsgi-py3为Apache 2.4安装mod_wsgi

I used: sudo apt-get install libapache2-mod-wsgi-py3 to install mod_wsgi for Apache 2.4

我使用: ./configure --with-python=/usr/local/bin/python3.6makemake install一起为Python 3.6安装mod_wsgi

I used: ./configure --with-python=/usr/local/bin/python3.6 and make with make install to install mod_wsgi for Python 3.6

我一定做错了-请纠正我!

这是我的Apache错误日志(已清除了一点)-是的,我知道它在f"字符串行上失败(python 3.6功能不在3.5中)

Here is my Apache Error Log (cleaned a bit) - and yes I know it fails on the f"" string line (python 3.6 feature not in 3.5)

[wsgi:warn] mod_wsgi: Compiled for Python/3.5.1+.
[wsgi:warn] mod_wsgi: Runtime using Python/3.5.2.
[wsgi:warn] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[wsgi:warn] AH00094: Command line: '/usr/sbin/apache2'
[wsgi:error] mod_wsgi (pid=12963): Target WSGI script '/home/jamin/www/dev.tir.com/tir/tir/wsgi.py' cannot be loaded as Python module.
[wsgi:error] mod_wsgi (pid=12963): Exception occurred processing WSGI script '/home/jamin/www/dev.tir.com/tir/tir/wsgi.py'.
[wsgi:error] Traceback (most recent call last):
[wsgi:error]   File "/home/jamin/www/dev.tir.com/tir/tir/wsgi.py", line 21, in <module>
[wsgi:error]     application = get_wsgi_application()
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[wsgi:error]     django.setup(set_prefix=False)
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
[wsgi:error]     apps.populate(settings.INSTALLED_APPS)
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/apps/registry.py", line 116, in populate
[wsgi:error]     app_config.ready()
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/contrib/admin/apps.py", line 23, in ready
[wsgi:error]     self.module.autodiscover()
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
[wsgi:error]     autodiscover_modules('admin', register_to=site)
[wsgi:error]   File "/home/jamin/www/dev.tir.com/py361ve/lib/python3.6/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
[wsgi:error]     import_module('%s.%s' % (app_config.name, module_to_search))
[wsgi:error]   File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[wsgi:error]     return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error]   File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[wsgi:error]   File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[wsgi:error]   File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
[wsgi:error]   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[wsgi:error]   File "<frozen importlib._bootstrap_external>", line 665, in exec_module
[wsgi:error]   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[wsgi:error]   File "/home/jamin/www/dev.tir.com/tir/company/admin.py", line 13, in <module>
[wsgi:error]     from .forms import AdminInteractionForm
[wsgi:error]   File "/home/jamin/www/dev.tir.com/tir/company/forms.py", line 87
[wsgi:error]     resp = f"Hi {user.first_name}, you'll need to login to send any more suggestions. \\
[wsgi:error]                              \\n\\nFirst Time? Check your email/spam for login instructions from us."
[wsgi:error]                                                                                        
[wsgi:error]                                                                                                   ^
[wsgi:error] SyntaxError: invalid syntax

*同时tir.com是我实际网站的简写-我与该域没有任何关系

*also tir.com is shorthand for my actual site - i do not have anything to do with that domain

推荐答案

执行以下操作.

卸载系统的mod_wsgi软件包.

Uninstall your system mod_wsgi package.

sudo apt-get remove libapache2-mod-wsgi-py3

使用pip安装mod_wsgi,最好安装到Python虚拟环境中.确保pip适用于您要使用的Python版本.

Install mod_wsgi using pip, preferably into a Python virtual environment. Ensure pip is for the version of Python you want to use.

pip install mod_wsgi

显示要添加到Apache配置文件的配置,以通过运行以下命令来加载此mod_wsgi:

Display the config to add to Apache configuration file to load this mod_wsgi by running:

mod_wsgi-express module-config

采用上述命令的输出以显示配置并添加到Apache配置中.

Take the output of above command to display config and add to Apache configuration.

向Apache添加配置,以加载一个Hello World WSGI应用程序以测试其工作.

Add configuration to Apache to load a hello world WSGI application to test it works.

在以下位置查看基于pip的安装的详细信息:

See details for pip based install in:

这篇关于在具有Python 3.6,Apache 2.4和Django 1.11的Ubuntu上安装mod_wsgi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆