如何使用"pip"安装psycopg2.在Python上? [英] How to install psycopg2 with "pip" on Python?

查看:205
本文介绍了如何使用"pip"安装psycopg2.在Python上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 virtualenv ,我需要安装"psycopg2".

I'm using virtualenv and I need to install "psycopg2".

我已经执行以下操作:

pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160

我收到以下消息:

Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
  Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
  Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
    Error: pg_config executable not found.

    Please add the directory containing pg_config to the PATH
    or specify the full executable path with the option:

        python setup.py build_ext --pg-config /path/to/pg_config build ...

    or with the pg_config option in 'setup.cfg'.
    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 top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt

writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt

writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'

warning: manifest_maker: standard file '-c' not found

Error: pg_config executable not found.



Please add the directory containing pg_config to the PATH

or specify the full executable path with the option:



    python setup.py build_ext --pg-config /path/to/pg_config build ...



or with the pg_config option in 'setup.cfg'.

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log

我的问题,我只需要这样做才能使psycopg2正常工作?

My question, I only need to do this to get the psycopg2 working?

python setup.py build_ext --pg-config /path/to/pg_config build ...

推荐答案

注意:早在不久之前,PyPI中就有Windows的二进制轮子,因此这不再是Windows用户的问题.以下是针对Linux和Mac用户的解决方案,因为他们中的许多人都是通过网络搜索找到这篇文章的.

Note: Since a while back, there are binary wheels for Windows in PyPI, so this should no longer be an issue for Windows users. Below are solutions for Linux, Mac users, since lots of them find this post through web searches.

安装psycopg2-binary PyPI软件包,它具有适用于Linux和Mac OS的Python滚轮.

Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.

pip install psycopg2-binary


选项2

安装用于从源代码构建psycopg2软件包的先决条件:


Option 2

Install the prerequsisites for building the psycopg2 package from source:

sudo apt install libpq-dev python3-dev

例如,您可能需要安装python3.8-dev或类似版本. Python 3.8.

You might need to install python3.8-dev or similar for e.g. Python 3.8.

sudo apt install libpq-dev python-dev

如果还不够,请尝试

sudo apt install build-essential

sudo apt install postgresql-server-dev-all

在再次安装psycopg2之前.

as well before installing psycopg2 again.

请参见 Banjer的答案

1 真的吗?是2020年

1 Really? It's 2020

这篇关于如何使用"pip"安装psycopg2.在Python上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆