简体   繁体   English

使用 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

How do I get mod_wsgi for Apache2 that was compiled for Python 3.6.1?如何获得为 Python 3.6.1 编译的 Apache2 的 mod_wsgi?

(or any future Python version) (或任何未来的 Python 版本)

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我正在使用带有 Django 1.11 的 Python 3.6.1 虚拟环境,并且一切都根据 Apache 错误日志工作,除了 Apache 2.4 的 mod_wsgi 是为 Python/3.5.1+ 编译的,并且使用的是 Python/3.5.2 所以我的 Python 3.6 .1 代码失败,因为我使用了 3.5.2 中不可用的新功能

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)...尽管 mod_wsgi 似乎没有使用我的 Python 3.6.1 虚拟环境(尽管它试图将它用于 Django 根据到错误日志)...

I used: sudo apt-get install libapache2-mod-wsgi-py3 to install mod_wsgi for Apache 2.4我使用: sudo apt-get install libapache2-mod-wsgi-py3为 Apache 2.4 安装 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我使用: ./configure --with-python=/usr/local/bin/python3.6makemake install安装mod_wsgi的Python的3.6

I must be doing something wrong - please correct me!我一定是做错了什么 - 请纠正我!

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)这是我的 Apache 错误日志(清理了一下) - 是的,我知道它在 f"" 字符串行上失败(python 3.6 功能不在 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

*also tir.com is shorthand for my actual site - i do not have anything to do with that domain * tir.com 也是我实际站点的简写 - 我与该域没有任何关系

Do the following.请执行下列操作。

Uninstall your system mod_wsgi package.卸载您的系统 mod_wsgi 包。

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

Install mod_wsgi using pip , preferably into a Python virtual environment.使用pip安装 mod_wsgi,最好安装到 Python 虚拟环境中。 Ensure pip is for the version of Python you want to use.确保pip适用于您要使用的 Python 版本。

pip install mod_wsgi

Display the config to add to Apache configuration file to load this mod_wsgi by running:通过运行以下命令显示要添加到 Apache 配置文件以加载此 mod_wsgi 的配置:

mod_wsgi-express module-config

Take the output of above command to display config and add to Apache configuration.获取上述命令的输出以显示配置并添加到 Apache 配置。

Add configuration to Apache to load a hello world WSGI application to test it works.将配置添加到 Apache 以加载 hello world WSGI 应用程序以测试它的工作原理。

See details for pip based install in:有关基于pip的安装的详细信息,请参见:

When I have used the @Graham Dumpleton suggestion to install the mod_wsgi using pip , got this error:当我使用@Graham Dumpleton 建议使用pip安装mod_wsgi ,出现此错误:

RuntimeError: The 'apxs' command appears not to be installed or is not executable.
Please check the list of prerequisites in the documentation for this package and
install any missing Apache httpd server packages.

To successfully compile and install the mod_wsgi through pip , I need to install the apache2-dev package on Ubuntu:要通过pip成功编译和安装mod_wsgi ,我需要在 Ubuntu 上安装apache2-dev包:

sudo apt-get install -y apache2-dev

On CentOS/Red Hat:在 CentOS/Red Hat 上:

sudo yum install httpd-devel

After that pip install mod_wsgi completes successfully.之后pip install mod_wsgi成功完成。

Hope that might help others.希望这可以帮助其他人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NameError:名称&#39;hasattr&#39;未定义 - Python3.6,Django1.11,Ubuntu16-17,Apache2.4,mod_wsgi - NameError: name 'hasattr' is not defined - Python3.6, Django1.11, Ubuntu16-17, Apache2.4, mod_wsgi Python / Django-使用mod_wsgi启动Apache - Python/Django - Starting apache with mod_wsgi Django,python,mod_wsgi和Apache工作者 - Django, python, mod_wsgi and Apache worker 数据库连接错误:Centos 6 / Apache 2.4 / Postgres 9.4 / Django 1.9 / mod_wsgi 3.5 / python 2.7 - Database Connect Error: Centos 6 / Apache 2.4 / Postgres 9.4 / Django 1.9 / mod_wsgi 3.5 / python 2.7 AH00112:警告-Centos 6 / Apache 2.4 / Django 1.9 / mod_wsgi 3.5 / python 2.7 - AH00112: Warning - Centos 6 / Apache 2.4 / Django 1.9 / mod_wsgi 3.5 / python 2.7 Django 1.6应用在Apache 2.4和python 3.3上运行mod_wsgi时出现错误500 - Error 500 with django 1.6 app running on apache 2.4 and python 3.3 with mod_wsgi Django,apache和mod_wsgi - Django, apache and mod_wsgi Ubuntu-Python-Apache2-Mod_WSGI-Django:没有名为/ TypeError / TemplateSyntaxError /&#39;str&#39;对象的模块不可调用 - Ubuntu - Python - Apache2 - Mod_WSGI - Django: No module named / TypeError / TemplateSyntaxError / 'str' object is not callable 如何在Ubuntu中将mod_wsgi安装到特定的python版本? - How to install mod_wsgi to specific python version in Ubuntu? Django/mod_wsgi/Apache - mod_wsgi 没有使用为它编译的 Python 版本 - “ModuleNotFoundError: No module named 'math'” - Django/mod_wsgi/Apache - mod_wsgi is not using the Python version it was compiled for - “ModuleNotFoundError: No module named 'math' ”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM