psycopg2安装问题

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

启动Django服务器时,出现以下错误:

Failed to get real commands on module "mysite": python process died with code 1: Traceback (most recent call last):
  File "C:\Users\Jack\Anaconda3\envs\mysite\lib\site-packages\django\db\backends\postgresql\base.py", line 25, in <module>
    import psycopg2 as Database
  File "C:\Users\Jack\Anaconda3\envs\mysite\lib\site-packages\psycopg2\__init__.py", line 50, 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 "C:\Program Files\JetBrains\PyCharm 2019.3.1\plugins\python\helpers\pycharm\_jb_manage_tasks_provider.py", line 25, in <module>
    django.setup()
  File "C:\Users\Jack\Anaconda3\envs\mysite\lib\site-packages\django\__init__.py", line 24, in setup

安装磁带库后,当我检查psycopg2目录时,__init__.py包含from psycopg2._psycopg import ...。但是_psycopg.dll目录中没有psycopg2文件。可能的错误?

我的settings.py的一部分:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "database1",
        "USER": "postgres",
        "PASSWORD": "123456",
        "HOST": "127.0.0.1",
        "PORT": "5432"
    }
}

正在使用:

Windows 10

PyCharm

Anaconda

Python 3.8.3

psycopg2 2.8.4

Django 3.0.3

PostgreSQL

django postgresql psycopg2
1个回答
0
投票

好吧,我终于可以使用它了。

我不得不从Anaconda环境切换到Virtualenv环境,并使用Pip进行安装,并保持相同的设置。

所以问题出在Anaconda处理psycopg2的方式上,还是库本身有问题,因为Anaconda上<< psycopg2的最新版本早于0.0.x

版本差异很小,但可能缺少修补程序。
© www.soinside.com 2019 - 2024. All rights reserved.