导入错误:无法从“psycopg2._psycopg”导入名称“编码”

问题描述 投票:0回答:1

我遇到了这个问题,谷歌没有给出答案...

我有: Linux 3.10.0-1160.95.1.el7.x86_64;姜戈 3.2.6; Python 3.9; psycopg2 2.9.9; nginx/1.14.0;

日志:

[Wed Nov 15 11:20:13.904181 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] mod_wsgi (pid=63994): Failed to exec Python script file '/home/users/###/###/domains/###/django.wsgi'.
[Wed Nov 15 11:20:13.904240 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] mod_wsgi (pid=63994): Exception occurred processing WSGI script '/home/users/###/###/domains/###/django.wsgi'.
[Wed Nov 15 11:20:13.906201 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] Traceback (most recent call last):
[Wed Nov 15 11:20:13.906243 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
[Wed Nov 15 11:20:13.906250 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     import psycopg2 as Database
[Wed Nov 15 11:20:13.906261 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/psycopg2/__init__.py", line 67, in <module>
[Wed Nov 15 11:20:13.906267 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     from psycopg2 import extensions as _ext
[Wed Nov 15 11:20:13.906276 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/psycopg2/extensions.py", line 50, in <module>
[Wed Nov 15 11:20:13.906281 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     from psycopg2._psycopg import (                             # noqa
[Wed Nov 15 11:20:13.906301 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] ImportError: cannot import name 'encodings' from 'psycopg2._psycopg' (/home/users/###/###/###/env/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-x86_64-linux-gnu.so)
[Wed Nov 15 11:20:13.906315 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] 
[Wed Nov 15 11:20:13.906319 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] During handling of the above exception, another exception occurred:
[Wed Nov 15 11:20:13.906323 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] 
[Wed Nov 15 11:20:13.906333 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] Traceback (most recent call last):
[Wed Nov 15 11:20:13.906397 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/domains/###/django.wsgi", line 6, in <module>
[Wed Nov 15 11:20:13.906403 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     from warehouse.wsgi import application
[Wed Nov 15 11:20:13.906413 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/###/###/wsgi.py", line 16, in <module>
[Wed Nov 15 11:20:13.906418 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     application = get_wsgi_application()
[Wed Nov 15 11:20:13.906428 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Wed Nov 15 11:20:13.906433 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     django.setup(set_prefix=False)
[Wed Nov 15 11:20:13.906442 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
[Wed Nov 15 11:20:13.906447 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     apps.populate(settings.INSTALLED_APPS)
[Wed Nov 15 11:20:13.906457 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
[Wed Nov 15 11:20:13.906471 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     app_config.import_models()
[Wed Nov 15 11:20:13.906481 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
[Wed Nov 15 11:20:13.906486 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     self.models_module = import_module(models_module_name)
[Wed Nov 15 11:20:13.906495 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
[Wed Nov 15 11:20:13.906500 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     return _bootstrap._gcd_import(name[level:], package, level)
[Wed Nov 15 11:20:13.906509 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
[Wed Nov 15 11:20:13.906514 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[Wed Nov 15 11:20:13.906523 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
[Wed Nov 15 11:20:13.906528 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     class AbstractBaseUser(models.Model):
[Wed Nov 15 11:20:13.906537 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
[Wed Nov 15 11:20:13.906542 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     new_class.add_to_class('_meta', Options(meta, app_label))
[Wed Nov 15 11:20:13.906551 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
[Wed Nov 15 11:20:13.906556 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     value.contribute_to_class(cls, name)
[Wed Nov 15 11:20:13.906565 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/models/options.py", line 207, in contribute_to_class
[Wed Nov 15 11:20:13.906569 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Nov 15 11:20:13.906579 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
[Wed Nov 15 11:20:13.906584 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     return getattr(self._connections[self._alias], item)
[Wed Nov 15 11:20:13.906593 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
[Wed Nov 15 11:20:13.906597 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     conn = self.create_connection(alias)
[Wed Nov 15 11:20:13.906607 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/utils.py", line 204, in create_connection
[Wed Nov 15 11:20:13.906611 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     backend = load_backend(db['ENGINE'])
[Wed Nov 15 11:20:13.906626 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
[Wed Nov 15 11:20:13.906633 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     return import_module('%s.base' % backend_name)
[Wed Nov 15 11:20:13.906646 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/usr/lib64/python3.9/importlib/__init__.py", line 127, in import_module
[Wed Nov 15 11:20:13.906655 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     return _bootstrap._gcd_import(name[level:], package, level)
[Wed Nov 15 11:20:13.906665 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]   File "/home/users/###/###/###/env/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 29, in <module>
[Wed Nov 15 11:20:13.906670 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0]     raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Wed Nov 15 11:20:13.906687 2023] [wsgi:error] [pid 63994] [client 5.180.19.143:0] django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: cannot import name 'encodings' from 'psycopg2._psycopg' (/home/users/###/###/###/env/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-x86_64-linux-gnu.so)
> /builddir/build/BUILD/Python-3.9.0/Modules/_decimal/libmpdec/context.c:57: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time

如果删除“www”,很容易导致此错误。从地址栏。 这真是太奇怪了。你遇到过这样的事情吗?

我重新安装了 psycopg2 - 它没有效果。

python django nginx web psycopg2
1个回答
0
投票

我要结束这个问题,因为我找到了最好的解决方案 - 更改托管。在我的旧主机上,操作系统的配置是最糟糕的。不知怎的,发生了冲突。更换主机后就没有问题了

© www.soinside.com 2019 - 2024. All rights reserved.