Postgresql 如何安装";psycopg2“;在这种情况下

Postgresql 如何安装";psycopg2“;在这种情况下,postgresql,ubuntu-16.04,psycopg2,libpq,Postgresql,Ubuntu 16.04,Psycopg2,Libpq,我正在为我的项目安装psycopg2软件包 pip安装psycopg2 然后我得到了这个错误: Collecting psycopg2 Using cached https://pypi.tuna.tsinghua.edu.cn/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz Complete output from command py

我正在为我的项目安装
psycopg2
软件包

pip安装psycopg2

然后我得到了这个错误:

Collecting psycopg2
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/23/7e/93c325482c328619870b6cd09370f6dbe1148283daca65115cd63642e60f/psycopg2-2.8.2.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info/psycopg2.egg-info
    writing pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    /home/sl/anaconda3/envs/pd36/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
      warnings.warn(msg)
    Error: b'You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.\n'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-r7a1yqf1/psycopg2/
You are using pip version 9.0.1, however version 19.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
它说我需要在安装
psycopg2
之前安装
libpq-dev
(对吗?)

sudo apt get install libpq dev

然后它给了我

Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libpq-dev : Depends: libpq5 (= 9.5.17-0ubuntu0.16.04.1) but 10.5-1.pgdg16.04+1 is to be installed
E: Unable to correct problems, you have held broken packages.
意味着我需要安装
libpq5=9.5.17-0ubuntu0.16.04.1。

但是,我无法安装libpq5的9.5.xx版本,因为我的

postgresql数据库最高达10.xx,并且安装了

libpq5=9.5.xx
将重新安装我的数据库到9.5.xx,我不能让它发生

发生在我的数据库上。最后,我无法安装
psycopg2

这是怎么发生的,我怎样才能正确安装psycopg2,救救我

我已尝试
安装python-psycopg2
,但仍然无法导入
psycopg2
在我的项目中


我正在使用
python3.6.5
ubuntu16.04

尝试
sudo-apt-get-autoremove
来摆脱
E:无法纠正问题,您持有的软件包已损坏。
@ApoorvGoyal谢谢,但这无法解决问题。您是否再次尝试运行
sudo-apt-get-install-libpq-dev
,它仍然是一样的。似乎您是从某个存储库(而不是默认的系统存储库)安装postgresql的。可能是PGDG回购?从安装服务器本身的同一存储库安装libpq dev。请尝试
sudo apt get autoremove
以摆脱
E:无法纠正问题,您持有的软件包已损坏。
@ApoorvGoyal谢谢,但这并不能解决问题。您是否尝试再次运行
sudo apt get install libpq dev
?@ApoorvGoyal当然,它仍然是一样的。似乎您是从默认系统存储库以外的其他存储库安装postgresql的。可能是PGDG回购?从与安装服务器本身相同的存储库安装libpq dev。