如何使用“pip"安装 psycopg2在 Python 上? [英] How to install psycopg2 with "pip" on 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-infopsycopg2.egg-info
writing pip-egg-infopsycopg2.egg-infoPKG-INFO
writing top-level names to pip-egg-infopsycopg2.egg-info op_level.txt
writing dependency_links to pip-egg-infopsycopg2.egg-infodependency_links.txt
writing manifest file 'pip-egg-infopsycopg2.egg-infoSOURCES.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 SettingsanlopesApplication Datapipp
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
包的先决条件:
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 的回答
这篇关于如何使用“pip"安装 psycopg2在 Python 上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!