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

f8rj6qna  于 2022-11-16  发布在  Apache
关注(0)|答案(2)|浏览(628)

我尝试在Apache 2服务器上部署我的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-默认.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配置文件

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) ####

接下来我可以尝试什么?

xu3bshqb

xu3bshqb1#

模块未找到错误:没有模块名为'backports'我解决了这个错误,首先从我的项目中删除backports.zoneinfo包,然后通过键入pip install backports.zoneinfo[tzdata]重新安装

d7v8vwbk

d7v8vwbk2#

最后,我通过为Django项目中的所有文件和目录授予权限解决了这个问题。

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

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

相关问题