在psycop2成功脱离联盟后,在我的pycharm终端中运行任何命令时,导入_psycopg时DLL加载失败



我已经在我的virtualenv上安装了psycop2。

然后在我的pycharm终端中运行任何命令后,我得到了这个错误:

(venv) C:UsersADMINPycharmProjectsdjango_pro_postgresdjango_project>python manage.py makemigrations
Traceback (most recent call last):
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbbackendspostgresqlbase.py", line 25, in <module>
import psycopg2 as Database
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagespsycopg2__init__.py", line 51, in <module>
from psycopg2._psycopg import (                     # noqa
ImportError: DLL load failed while importing _psycopg: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangocoremanagement__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangocoremanagement__init__.py", line 377, in execute
django.setup()
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjango__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangoappsregistry.py", line 114, in populate
app_config.import_models()
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangoappsconfig.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:UsersADMINAppDataLocalProgramsPythonPython38-32libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangocontribauthmodels.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangocontribauthbase_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbmodelsbase.py", line 121, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbmodelsbase.py", line 325, in add_to_class
value.contribute_to_class(cls, name)
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbmodelsoptions.py", line 208, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodb__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbutils.py", line 207, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbutils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:UsersADMINAppDataLocalProgramsPythonPython38-32libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:UsersADMINPycharmProjectsdjango_pro_postgresvenvlibsite-packagesdjangodbbackendspostgresqlbase.py", line 29, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: DLL load failed while importing _psycopg: The specified module could not be found.

我已在设置中配置了数据库详细信息。py:

# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'overiq',
'USER' : 'postgres',
'PASSWORD' : '123456',
'HOST' : 'localhost'
}
}

错误:django.core.exceptions.ImproverlyConfigure:加载psycopg2模块时出错:导入_psycopg时DLL加载失败:找不到指定的模块。

使用的IDE:PyCharm

Python版本:3.8.2

Django版本:3.0.5

操作系统:Windows 8.1(32位(

我已经检查了所有的设置,但我仍然有同样的问题。有人能建议我如何消除这个错误吗

我在这里有两个建议

  1. 使用'ENGINE':'django.db.backends.postgresql_psycopg2'
  2. 卸载原始psycopg2-binary,执行命令pip install psycopg2-binary

我以前使用的Python版本是3.6。当我更改为3.8时,出现了这个问题。我试着安装了最新的psycopg2-binary,它被证明是有效的。

相关内容

  • 没有找到相关文章