Importerror:无法导入名称' Zoneinfo'从``backports' (未知位置)

发布于 2025-02-13 17:08:53 字数 4505 浏览 0 评论 0原文

我正在尝试在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

i i正确安装了mod_wsgi,适用于python 3.88 .10

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

我接下来可以尝试什么?

I am trying to deploy my Django model on an Apache2 server and it is running well on 'ip':8000. But when i am trying to run without 8000 port after completing all prerequisites i am getting this error

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

These are my all working files

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

I installed mod_wsgi correctly for Python 3.8.10

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

Also I have given permissions to all the working files but nothing happened

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

What can I try next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

起风了 2025-02-20 17:08:53

ModulenotFoundError:没有名为“ Backports”的模块
我首先从项目中删除包装backports.zoneinfo来解决此错误
然后通过键入重新安装
PIP安装backports.zoneinfo [tzdata]

ModuleNotFoundError: No module named 'backports'
I solved this error by first removing the package backports.zoneinfo from my project
and then re-install by typing
pip install backports.zoneinfo[tzdata]

秋凉 2025-02-20 17:08:53

最后,我通过在我的Django项目中对所有文件和目录的权限提供了这个问题。使用此命令,

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

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

Finally I have solved this issue by giving permissions to all files and directories in my Django project. Using this command

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

It solved my many errors related to modules. If you are new to Apache deployment make sure you give right permissions to all files in directories.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文