Sourav Gupta
Sourav Gupta

Reputation: 257

Error while installing psycopg2 in Windows

I tried to install psycopg2 as: pip install psycopg2

It was giving error for pg_config. I checked some stackoverflow notes and installed PostgreSQL. Added the path of pg_config in $PATH.

Now it is giving the below error:

LINK : fatal error LNK1181: cannot open input file 'libpq.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x64\\link.exe' failed with exit status 1181

Any help on this?

Upvotes: 3

Views: 9415

Answers (5)

Chukwuemeka
Chukwuemeka

Reputation: 176

In case you are here in 2020, this is a problem with version 3.8 of python. I had the issue recently. Try using virtualenv so that you can use lower versions of python in your workspace until psycopg2 is supported fully on Python version 3.8

Upvotes: 0

Suraj Gudaji
Suraj Gudaji

Reputation: 31

For Windows users, to install the psycopg2 without any errors first install Python 3.7.4 version and then install psycopg2 using command pip install psycopg2 as it worked complete fine with me. I think there is some issue in Python 3.8.0 version onwards because while installing psycopg it is showing an error in setup wheels.

Upvotes: 0

Shadhana Palaniswami
Shadhana Palaniswami

Reputation: 11

Go to https://pypi.org/project/psycopg2 in release history and select the version you want to download.

There will be a table with files and the versions of python that can be compatible with the selected version.

Now download the wheel file that matches your system configuration(mac/linux/win-32/win-64)

I did this and was able to download the package.

For windows10(64-bit), download psycopg2-2.7.7-cp36-cp36m-win_amd64.whl (998.5 kB), in case you have selected 2.7.7

Upvotes: 1

Sourav Gupta
Sourav Gupta

Reputation: 257

I found the issue.... I was using Python 3.7 version. Looks like the latest stable version of psycopg2 (2.7.4) is not yet supported on Python 3.7. It is supported till 3.6

I downgraded my python to 3.6.5 in Anaconda and also to 2.7.15 through PyCharm. I was able to install psycopg2 in both and use them.

Upvotes: 1

Jair
Jair

Reputation: 106

Have you tried reinstall without pip?

sudo apt-get install python3-psycopg2

EDIT: Since you're on windows:

You can try this if you're using python 2.7:

pip uninstall psycopg2
pip install git+https://github.com/nwcell/psycopg2-windows.git@win64-py27#egg=psycopg2

If you're using python 3.4:

pip uninstall psycopg2
pip install git+https://github.com/nwcell/psycopg2-windows.git@win64-py34#egg=psycopg2

More info here.

If you prefer, you can download the installer (.exe) and install it. You can find it here.

Upvotes: 5

Related Questions