简体   繁体   English

无法在 Windows 上安装 psycopg2

[英]Unable to install psycopg2 on Windows

I work in a office where the PostgreSQL has been installed on server.我在服务器上安装了 PostgreSQL 的办公室工作。 On my windows machine, I have pgAdmin III 1.20 installed to access the database.在我的 Windows 机器上,我安装了 pgAdmin III 1.20 来访问数据库。 I am trying to install psycopg2 in my windows system.我正在尝试在我的 Windows 系统中安装 psycopg2。 I get this error:我收到此错误:

C:\users\Tony> pip install psycopg2
Collecting psycopg2
Using cached psycopg2-2.6.1.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 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 in c:\users\Tony\appdata\local\temp\pip-build-dobxew\psycopg2

I know that pg_config is available in the bin folder of the PostgreSQL.我知道 pg_config 在 PostgreSQL 的 bin 文件夹中可用。 But I cannot access that location in server.但是我无法访问服务器中的那个位置。 Without pg_config file, I am unable to install psycopg2 in my local windows machine.没有 pg_config 文件,我无法在本地 Windows 机器上安装 psycopg2。 I read somewhere that libpq.dll is required while building psycopg2.So I have added path of libpq.dll present in pgAdmin III 1.20 into my system path.(C:\\Program Files (x86)\\pgAdmin III\\1.20) How to access the PostgreSQL database using Python then?我在某处读到在构建 psycopg2 时需要 libpq.dll。所以我已将 pgAdmin III 1.20 中存在的 libpq.dll 路径添加到我的系统路径中。(C:\\Program Files (x86)\\pgAdmin III\\1.20) 如何访问使用Python 的PostgreSQL 数据库呢?

The following will install prebuilt binaries for windows from this site .下面将从此站点安装用于 Windows 的预构建二进制文件。

pip install pipwin 
pipwin install psycopg2

对于所有在 2019 年遇到相同问题的人,现在通过 pip 安装它的正确方法是:

pip install psycopg2-binary

使用此页面下载适用于 Windows 的预构建二进制文件。

run this command:运行这个命令:

python -m pip install Psycopg2

Note:笔记:

Open the commandprompt in the same folder as project在与项目相同的文件夹中打开命令提示符

Download psycopg2 version for your python and windows from here win-psycopg从这里为您的 python 和 windows 下载psycopg2版本win-psycopg

Do NOT double-click the package to run.不要双击要运行的包。 Instead, use easy_install from either setuptools or distribute .相反,请使用setuptools分发中的easy_install 。

C:\> easy_install psycopg2-2.6.1.win32-py2.7-pg9.4.4-release.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM