首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ImportError:无法从“backport”(未知位置)导入名称“zoneinfo”

ImportError:无法从“backport”(未知位置)导入名称“zoneinfo”
EN

Stack Overflow用户
提问于 2022-07-07 11:54:36
回答 2查看 777关注 0票数 0

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

代码语言:javascript
复制
[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

代码语言:javascript
复制
<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

代码语言:javascript
复制
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

我为Python3.8.10正确地安装了mod_wsgi

#wsgi.py

代码语言:javascript
复制
 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()

而且,我已经给了所有工作文件的权限,但是什么都没有发生。

代码语言:javascript
复制
#### 
    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) ####

接下来我能试试什么?

EN

回答 2

Stack Overflow用户

发布于 2022-09-23 11:38:25

ModuleNotFoundError:没有名为“backports”的模块,我首先从项目中删除包backports.zoneinfo,然后通过输入pip backports.zoneinfotzdata重新安装,从而解决了这个错误。

票数 1
EN

Stack Overflow用户

发布于 2022-07-11 16:34:51

最后,我通过对Django项目中的所有文件和目录授予权限来解决这个问题。使用此命令

代码语言:javascript
复制
find /root/novo-ai-api-main -type d -exec chmod 755 {} \;

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72897383

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档