导入错误:无法从'backports'(未知位置)导入名称'zoneinfo'



我正在尝试在Apache2服务器上部署我的Django模型,它在'ip':8000上运行良好。但是当我在完成所有先决条件后试图在没有8000端口的情况下运行时,我得到了这个错误

[Thu Jul 07 10:18:36.178228 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Thu Jul 07 10:18:36.178240 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]     return _bootstrap._gcd_import(name[level:], package, level)
[Thu Jul 07 10:18:36.178247 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]   File "/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 20, in <module>
[Thu Jul 07 10:18:36.178253 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]     from django.db.backends.base.base import BaseDatabaseWrapper, timezone_constructor
[Thu Jul 07 10:18:36.178260 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]   File "/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages/django/db/backends/base/base.py", line 12, in <module>
[Thu Jul 07 10:18:36.178277 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245]     from backports import zoneinfo
[Thu Jul 07 10:18:36.178308 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] ImportError: cannot import name 'zoneinfo' from 'backports' (unknown location)

这些是我所有的工作文件

000 - default.conf

<VirtualHost *:80>
#ServerAdmin webmaster@localhost
DocumentRoot /root/novo-ai-api-main

ErrorLog /root/novo-ai-api-main/error.log
CustomLog /root/novo-ai-api-main/access.log combine

<Directory /root/novo-ai-api-main/backend/server/server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static /root/novo-ai-api-main/static
<Directory /root/novo-ai-api-main/static>
Require all granted
</Directory>

WSGIScriptAlias / /root/novo-ai-api-main/backend/server/server/wsgi.py
WSGIDaemonProcess django_app python-path=/root/novo-ai-api-main/backend/server  python-home=/root/novo-ai-api-main/backend/dj/
WSGIProcessGroup django_app
</VirtualHost>

apache2.conf

apache2.conf

ServerRoot "/etc/apache2"
Timeout 300
MaxKeepAliveRequests 100
#KeepAliveTimeout: Number of seconds to wait for the next request from the
#same client on the same connection.
KeepAliveTimeout 5
#These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
LogLevel warn
#Sets the default security model of the Apache2 HTTPD server. It does
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

#AccessFileName .htaccess
#<FilesMatch "^.ht">
#Require all denied
#</FilesMatch>

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet

我正确安装了Python 3.8.10的mod_wsgi

# wsgi.py

import os, sys
import site
site.addsitedir('/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
application = get_wsgi_application()

我也给了所有工作文件权限,但是什么都没有发生

#### 
drwx--x--x  9 root     root       4096 Jun 16 22:05 .
drwxr-xr-x 19 root     root       4096 Jun 14 14:05 ..
drwxr-xr-x  3 root     root       4096 Jun 13 23:38 .local
drwxrwxr-x  8 root     root       4096 Jun 16 01:24 mod_wsgi-4.9.2
drwxr-xr-x  5 www-data www-data   4096 Jun 14 23:53 novo-ai-api-main <-(project)
drwxr-xr-x 5 www-data www-data     4096 Jun 14 23:14 backend
drw-r--r-- 8 www-data www-data     4096 Jun 14 00:33 static
drwxr-xr-x 6 www-data www-data 4096 Jun 14 00:16 dj <- (venv) ####

接下来我可以尝试什么?

ModuleNotFoundError:没有名为'backports'的模块我解决了这个错误,首先删除包后端口。Zoneinfo来自我的项目然后通过输入重新安装PIP install backports.zoneinfo[tzdata]

最后我通过给Django项目中的所有文件和目录赋予权限来解决这个问题。使用以下命令

find /root/novo-ai-api-main -type d -exec chmod 755 {} ;

它解决了我与模块相关的许多错误。如果您是Apache部署的新手,请确保您为目录中的所有文件赋予了正确的权限。

最新更新