我读了很多文章,但还是不知道我错过了什么。我在virtualenv运行一个Django网站。这是我的配置文件。网站地址被替换为<domain.com>,不能在这里使用。
配置
<VirtualHost *:80>
ServerAdmin sidharth@collaboration-management
ServerName <domain.com>
ServerAlias <domain.com>
DocumentRoot /home/sidharth/Downloads/gmcweb
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/sidharth/Downloads/gmcweb/static
<Directory /home/sidharth/Downloads/gmcweb/static>
Require all granted
</Directory>
<Directory /home/sidharth/Downloads/gmcweb/gmcweb>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess gmcweb python-home=/home/sidharth/Downloads/gmcwebenvlin python-path=/home/sidharth/Downloads/gmcweb
WSGIProcessGroup gmcweb
WSGIScriptAlias / /home/sidharth/Downloads/gmcweb/gmcweb/wsgi.py
</VirtualHost>
这是我的WSGI.py文件,没有改变任何东西从来没有更早
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gmcweb.settings')
application = get_wsgi_application()
Python版本
我的virtualenv python版本是3.9.5默认Google VM python版本是3.6.9
Python安装库
Package Version
------------------------ ---------
asgiref 3.4.0
attrs 21.2.0
autopep8 1.5.7
beautifulsoup4 4.9.3
certifi 2021.5.30
cffi 1.14.5
chardet 4.0.0
cryptography 3.4.7
defusedxml 0.7.1
Django 3.2.4
django-allauth 0.44.0
django-livereload-server 0.3.2
idna 2.10
jsonschema 3.2.0
oauthlib 3.1.1
pip 21.2.3
pycodestyle 2.7.0
pycparser 2.20
PyJWT 2.1.0
pyrsistent 0.18.0
python3-openid 3.2.0
pytz 2021.1
requests 2.25.1
requests-oauthlib 1.3.0
setuptools 57.4.0
six 1.16.0
soupsieve 2.2.1
sqlparse 0.4.1
toml 0.10.2
tornado 6.1
urllib3 1.26.6
我也安装了apache modwsgi sudo apt-get install python3-pip apache2 libapache2-mod-wsgi-py3
错误日志文件
[Thu Sep 23 15:05:06.554545 2021] [mpm_event:notice] [pid 32077:tid 140392561593280] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Thu Sep 23 15:05:06.554594 2021] [core:notice] [pid 32077:tid 140392561593280] AH00094: Command line: '/usr/sbin/apache2'
[Thu Sep 23 15:05:19.081581 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] mod_wsgi (pid=32617): Target WSGI script '/home/sidharth/Downloads/gmcweb/gmcweb/wsgi.py' c$
[Thu Sep 23 15:05:19.081638 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] mod_wsgi (pid=32617): Exception occurred processing WSGI script '/home/sidharth/Downloads/g$
[Thu Sep 23 15:05:19.081828 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] Traceback (most recent call last):
[Thu Sep 23 15:05:19.081849 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] File "/home/sidharth/Downloads/gmcweb/gmcweb/wsgi.py", line 12, in <module>
[Thu Sep 23 15:05:19.081853 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] from django.core.wsgi import get_wsgi_application
[Thu Sep 23 15:05:19.081867 2021] [wsgi:error] [pid 32617:tid 140392409851648] [remote 103.206.177.13:49604] ModuleNotFoundError: No module named 'django'
[Thu Sep 23 15:05:32.244779 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] mod_wsgi (pid=32617): Target WSGI script '/home/sidharth/Downloads/gmcweb/gmcweb/wsgi.py' c$
[Thu Sep 23 15:05:32.244845 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] mod_wsgi (pid=32617): Exception occurred processing WSGI script '/home/sidharth/Downloads/g$
[Thu Sep 23 15:05:32.244924 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] Traceback (most recent call last):
[Thu Sep 23 15:05:32.244946 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] File "/home/sidharth/Downloads/gmcweb/gmcweb/wsgi.py", line 12, in <module>
[Thu Sep 23 15:05:32.244951 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] from django.core.wsgi import get_wsgi_application
[Thu Sep 23 15:05:32.244966 2021] [wsgi:error] [pid 32617:tid 140392325842688] [remote 103.206.177.13:52916] ModuleNotFoundError: No module named 'django'
4条答案
按热度按时间uurv41yg1#
如果你遇到这样的问题,并且有多个Python版本,那么这就是问题所在。我创建了一个新的VM,其中包含了最新版本的Python,并且只有一个版本。它就像一个魅力。
当我们安装Mod_WSGI时,它将默认安装在环境路径上。
vd8tlhqk2#
错误提示您没有安装Django或者没有激活安装Django的虚拟环境。请确保您检查已安装的包列表并在其中找到Django,通过:
h43kikqp3#
libapache2-mod-wsgi-py3
只能在ubuntu 18中与python 3.6.9一起使用!!如果你的virtualenv使用其他版本的python,你应该从这个链接下载mod_wsgi
:mod_wsgi目前mod_wsgi的最新版本是4.9.0。请按照以下步骤操作:
camsedfj4#
在对这个问题进行了详尽的搜索和实践之后,我解决了我也面临的问题,我明白了
如果你的mod_wsgi是使用python安装的3.6比您的虚拟环境必须使用相同的Python版本创建,即。3.6.
mod_wsgi文档中也描述了这个问题,其中明确指出,它一次只适用于一个Python版本。因此,安装或编译mod_wsgi时使用的python版本必须与python虚拟环境相同。
django文档https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/modwsgi/中已经提供了其余的配置