25

I installed pyscopg3 on my venv using pip install psycopg[binary] as per the documentation but I still get an import error:

Exception has occurred: ImportError
no pq wrapper available.
Attempts made:
- couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
- couldn't import psycopg 'binary' implementation: DLL load failed while importing pq: The specified module could not be found.
- couldn't import psycopg 'python' implementation: libpq library not found

I'm running a Windows 10 machine. How can I solve this error?

wovano
  • 4,543
  • 5
  • 22
  • 49
ericshaaan
  • 251
  • 1
  • 3
  • 5

2 Answers2

20

I followed the psycopg installation steps from https://pypi.org/project/psycopg/

pip install --upgrade pip           # to upgrade pip

pip install "psycopg[binary,pool]"  # to install package and dependencies

it worked for me

ljoseph
  • 301
  • 2
  • 3
9

You need to install the command line tools on PostgreSQL on your Windows machine. Download the full server installer here: https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

You don't need to install the full server package, only command line tools in the installer options will be necessary:

enter image description here

After the installation, you need to add the PostgreSQL bin folder in your PATH environnement variable:

hit Windows Key+R at the same time to get command prompt. Then type sysdm.cpl, go to advanced and select "Environment Variables", in PATH add the path to : C:\Program Files\PostgreSQL\13\bin\ folder (or whatever folder you choose to install the PostreSQL commande line tools).

IMPORTANT: do not forget to close and restart your dev environnement (ie: VSCode, PyCharm, ...) to take the new environnement variable into account.

Note : This answer is related to Windows machine. For Linux the installation of a at least one postgresql-client-<version> package will be enough.

related to: https://stackoverflow.com/a/60369228/5341247

SuperPoney
  • 563
  • 6
  • 21
  • Did we need to install PostgreSQL commandline tools to use psycopg2 as well? I don't remember needing to install PostgreSQL commandline tools on my prod machine to run pyinstaller-compiled apps that used psycopg2, but now that I've refactored them to use psycopg 3, I needed to follow your advice to make them work again. – Nick Muise Dec 21 '22 at 19:25
  • @NickMuise I didn't use psycopg v2 in the past, so I cannot confirm. But to be honnest I don't think psycopg2 dev ships the DLL with their python package... So for me on you prod server you should have the package already installed or a postgresql database already setuped. – SuperPoney Dec 22 '22 at 16:47
  • Thanks SuperPoney. Installing the command line tools of PostgreSQL helped me to fix the psycopg[binary] install correctly :) – Davma Jan 30 '23 at 14:25