How to install psycopg2 with "pip" on Python?
Asked Answered
F

37

719

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

I have done the following:

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

And I have the following messages:

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

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 ...
Fulgurating answered 24/3, 2011 at 14:33 Comment(3)
Did it work when you tried python setup.py build_ext --pg-config /path/to/pg_config build ... ??Strenta
For python 3.4 or python 3.5, you have to install the corresponding verion's dev package like sudo apt install libpq-dev python3.4-dev or sudo apt install libpq-dev python3.5-devSandpit
psycopg2 remove this and add psycopg2-binary to the dependencies file and re-try.Stepdame
S
1248

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.


Option 1

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

pip install psycopg2-binary

Option 2

Install the prerequsisites for building the psycopg2 package from source:

Debian/Ubuntu

Python version Command Note
Default Python 3 sudo apt install libpq-dev python3-dev
Python 3.x sudo apt install libpq-dev python3.x-dev substitute x in command
Python 2 sudo apt install libpq-dev python-dev

If that's not enough, you might additionally need to install

sudo apt install build-essential

or

sudo apt install postgresql-server-dev-all

as well before installing psycopg2 again.

CentOS 6

See Banjer's answer

macOS

See nichochar's answer

Selfheal answered 27/3, 2011 at 15:25 Comment(24)
11.04: different errors, the same solution. Worship to dev versions!Loyal
@Loyal - The *-dev packages contain the files necessary to compile an application from source that uses the functions provided by the library (as psycopg2 uses the libpq and python libraries, among others).Selfheal
I'm using Ubuntu 12.04 LTS, and I also had to sudo apt-get install postgresql-server-dev-allFootgear
how can i install libpq-dev python-dev packages in opensuse?Ligule
Could someone please explain why not just the directory containing pg_config to the PATH (or use --pg-config)?Strenta
Works for me on Ubuntu 12.10.Menial
I found I only needed to install libpq-dev, which is fortunate, as python-dev wouldn't install.Quicksand
I'm missing something. I'm using virtualenv as a convenience to perform local installs because I don't have root privileges on my deployment server. Does anyone know the actual answer to the original question, because I do know that my machine and the deployment server do have the needed dependencies, I just won't have permission to re-deploy.Millwright
@DavidBerger if you have the libpq-dev and python-dev packages installed, your virtualenv's pip should install it just fine.Selfheal
@Selfheal Not entirely true. At least, I have the python modules I need in my site-packages, although I'm unsure how they got there. But pip crashes with the above error. Of course, my destination environment also has the necessary dependencies, so virtualenv --system-site-packages allows me to do what I need without pip install, but I didn't originally want to go that route.Millwright
As a note: this is an excellent example of why post-only answers should not be allowed. The link no longer works.Hanna
If you are here because you are having trouble installing psycopg2 into the python 3 Celery container from Dockerhub you will also need to install build-essential with sudo apt-get install -y build-essentialSessions
I had to do sudo apt-get install libpq-dev python3-dev as im using python3Walworth
On ubuntu 14.04.5 and python3 what worked for me was: sudo apt install libpq-dev python3-devMartella
@Tessaracter It's accepted because it's the correct answer. You can't install libpq-dev and python-dev with pip, you need to install both libpq-dev and python-dev before you run pip install psycopg2.Selfheal
This is not working for python 3.8, python 3.7 worked well.Rovit
@FawwazYusran You might have to install python3.8-dev or a similarly named package.Selfheal
Works on ubuntu 20.04. Thank you!Candida
So is Option 1 necessary and THEN Debian/Ubuntu step? or is that Debian/Ubuntu step a part of option 2?Fame
@Fame Everything below "Option 2" are specifics about "Option 2", as indicated using both h1/h2/h3 and <hr>Selfheal
Option #1 works on pypy as well.Respire
If you are on Ubuntu 20.04 or above, do install sudo apt-get install build-essentialKenn
On debian I didn't need the whole build-essential just a apt install gcc did the trickFerreous
sudo apt install postgresql-server-dev-all fixed in UBUNTU 22.04Cryptonymous
A
127

On CentOS, you need the postgres dev packages:

sudo yum install python-devel postgresql-devel

That was the solution on CentOS 6 at least.

Airedale answered 31/10, 2012 at 13:3 Comment(7)
This isn't just CentOS, I think. psycopg has native dependencies, so to build from source (which is what pip does), the PostgreSQL development libraries need to be there. (The C headers, maybe? I don't know much about compiling native code.)Livvi
I concur that this solves the problem on CentOS 6. I would like to add that I did have to add /usr/pgsql-9.3/bin to $PATH. Here is a post giving an example of how to do that. serverfault.com/questions/102932/…Laureate
For CentOS 7 and Python 3.4 I had to install "python34-devel". My answer to a related question: https://mcmap.net/q/64540/-psycopg2-fails-to-install-on-python-3-with-pip-issuing-a-fatal-errorIndirection
Worked on AWS EC2, with RHEL-based 64bit Amazon Linux/2.5.1Tough
For Python3 in Fedora use sudo yum install python36-devel (replace 36 with your version of Python 3).Hampton
Maybe worth mentioning that this installs the dependencies for psycopg2 and doesn't pip install it, so you actually have to pip install it after you install the dependencies.Rajah
If you have built python from source, you have to rebuild it after installing system dependencies.Prelude
S
108

If you're on a mac you can use homebrew

brew install postgresql

And all other options are here: http://www.postgresql.org/download/macosx/

Silverweed answered 31/10, 2013 at 16:26 Comment(3)
nichochar's answer and attomos's answer (install postgresql and modify path) together resolved the issue for me. the easiest way to edit the path is to run "sudo nano /etc/path" from your terminal.Donald
This does not install the postgresql in the virtualenv like the OP asked.Mendelevium
I don't think OP necessarily wanted postgres in the virtualenv. He said he is using virtualenv. I think he misunderstood that postgresql is a bigger service than simply a python library.Silverweed
N
91

On Mac Mavericks with Postgres.app version 9.3.2.0 RC2 I needed to use the following code after installing Postgres:

sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2

Novotny answered 22/12, 2013 at 1:51 Comment(9)
sudo PATH=$PATH:/Applications/Postgres93.app/Contents/MacOS/bin pip install psycopg2 [as of April 5, 2014]Crocodilian
Confirmed for Postgres.app 9.3.5 also :)Millsaps
With Postgres.app 9.3.5 Mac OS X Version 10.9.4, I had to add export PATH=${PATH}:/Applications/Postgres.app/Contents/Versions/9.3/bin/ to the ~/.bash_profile and open a new window before psycopg2 installed. The path specified by @Crocodilian doesn't exist for me and I just installed Postgres.app on my computer today [September 11,2014].Dyne
if you are using virtualenv you dont need 'sudo' so active your virtualenv and run 'PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2'Lorislorita
My case OS X Ver 10.9.4: sudo PATH=$PATH:/Library/PostgreSQL/9.2/bin pip install psycopg2Dartmouth
Yes, this worked for me too. After installing PostgreSQL, I had to set my path by doing PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2.Mating
Use the latest version: PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin pip install psycopg2Dona
Saved me ,For My Mac 10.13.3 ,python -v :2.7.10 pip -version :10.0.0 .The pip install psycopg2 was not workingUnchaste
sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin python3 -m pip install psycopg2 this workedResponsive
C
65

I recently configured psycopg2 on a windows machine. The easiest install is using a windows executable binary. You can find it at http://stickpeople.com/projects/python/win-psycopg/.

To install the native binary in a virtual envrionment, use easy_install:

C:\virtualenv\Scripts\> activate.bat
(virtualenv) C:\virtualenv\Scripts\> easy_install psycopg2-2.5.win32-py2.7-pg9.2.4-release.exe
Counterpressure answered 24/3, 2011 at 15:1 Comment(8)
Thanks for the reply. But I need to install to an virtual environment. Best Regard,Cementite
This trick (courtesy, Ned Batchelder) has helped me in the past to install from binaries to a virtualenvCounterpressure
Is there really no way to get "pip install psycopg2" working on Windows? Even if a patch to psycopg2 is necessary, it would be worth it.Indeterminate
I got this error when postgres was not installed on my machine - I installed postgres and the error went away ...Maidenly
the stickpeople link also discusses virtual env and points to a pip install version github.com/nwcell/psycopg2-windowsWhist
I'm using a windows and inside a virtualenv and the easy_install psycopg2 worked like a charm.Anabaptist
Thanks, easy_install worked. Only problem was that it added to "venv\Lib\site-packages\psycopg2-2.6.1-py3.4-win32.egg\" directory this psycopg2 module/directory. All i had to do was copy it to site-packages folderHoneysweet
Only @Whist comment solved my problem, however that linked repo is abandoned. Checkout this link for an updated solution (psycopg2.6.2 + Win64 + env)Spaniard
F
36

For Python 3 you should use sudo apt-get install libpq-dev python3-dev under Debian.

Fulgurating answered 3/10, 2012 at 18:39 Comment(2)
If you are on Ubuntu 20.04 or above, do install sudo apt-get install build-essentialKenn
For me python3 was referring to 3.10 but I was using 3.9 version, so I changed from python3-dev to python3.9-dev and it worked.Younger
R
28

This is what worked for me (On RHEL, CentOS:

sudo yum install postgresql postgresql-devel python-devel

And now include the path to your postgresql binary dir with you pip install:

sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2

Make sure to include the correct path. Thats all :)

UPDATE: For python 3, please install python3-devel instead of python-devel

Refreshment answered 20/11, 2014 at 15:14 Comment(4)
Note that I didn't need to update the PATH environment variable.Gerdagerdeen
You shouldn't have to if you reload your terminal session.Refreshment
Excelent Thank you so much .Giliane
If you are using Python 3 you'll need to install numbered Python devel packages. See: https://mcmap.net/q/64540/-psycopg2-fails-to-install-on-python-3-with-pip-issuing-a-fatal-errorIndirection
L
24

The answers so far are too much like magic recipes. The error that you received tells you that pip cannot find a needed part of the PostgreSQL Query library. Possibly this is because you have it installed in a non-standard place for your OS which is why the message suggests using the --pg-config option.

But a more common reason is that you don't have libpq installed at all. This commonly happens on machines where you do NOT have PostgreSQL server installed because you only want to run client apps, not the server itself. Each OS/distro is different, for instance on Debian/Ubuntu you need to install libpq-dev. This allows you to compile and link code against the PostgreSQL Query library.

Most of the answers also suggest installing a Python dev library. Be careful. If you are only using the default Python installed by your distro, that will work, but if you have a newer version, it could cause problems. If you have built Python on this machine then you already have the dev libraries needed for compiling C/C++ libraries to interface with Python. As long as you are using the correct pip version, the one installed in the same bin folder as the python binary, then you are all set. No need to install the old version.

Lamprey answered 17/1, 2015 at 19:41 Comment(1)
And about Os x? I mean, is based on Unix but I think can be different.School
P
21

If you using Mac OS, you should install PostgreSQL from source. After installation is finished, you need to add this path using:

export PATH=/local/pgsql/bin:$PATH

or you can append the path like this:

export PATH=.../:usr/local/pgsql/bin

in your .profile file or .zshrc file.

This maybe vary by operating system.

You can follow the installation process from http://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/

Proudlove answered 2/4, 2012 at 7:22 Comment(2)
Why from source instead of Homebrew?Fossilize
@Fossilize it was answered in 2012 and I believe I did try to install it with Homebrew at that time but it failed. Now, I've installed PostgreSQL using Homebrew without any problems.Proudlove
K
17

Run below commands and you should be fine

$ apt-get update
$ apt install python3-dev libpq-dev
$ pip3 install psycopg2
Kindig answered 18/6, 2021 at 11:4 Comment(1)
If you are on Ubuntu 20.04 or above, do install sudo apt-get install build-essentialKenn
A
14

On Debian/Ubuntu:

First install and build dependencies of psycopg2 package:

# apt-get build-dep python-psycopg2

Then in your virtual environment, compile and install psycopg2 module:

(env)$ pip install psycopg2
Allometry answered 6/9, 2015 at 14:27 Comment(0)
U
7

Before you can install psycopg2 you will need to install the python-dev package.

If you're working from Linux (and possibly other systems but i can't speak from experience) you will need to make sure to be quite exact about what version of python your running when installing the dev package.

For example when I used the command:

sudo apt-get install python3-dev

I still ran into the same error when trying to

pip install psycopg2

As I am using python 3.7 I needed to use the command

sudo apt-get install python3.7-dev

Once I did this I ran into no more issues. Obviously if your on python version 3.5 you would change that 7 to a 5.

Uncinate answered 20/5, 2019 at 14:42 Comment(2)
This should be the answer, sudo apt-get install python-x.x-dev fixed the issue.Saundrasaunter
If you are on Ubuntu 20.04 or above, do install sudo apt-get install build-essentialKenn
F
6

I've done this before where in windows you install first into your base python installation.

Then, you manually copy the installed psycopg2 to the virtualenv install.

It's not pretty, but it works.

Fabaceous answered 27/2, 2012 at 3:35 Comment(3)
can you elaborate please. Where do you get the psycopg2 at the first place?Photogene
windows binaries are available at stickpeople.com/projects/python/win-psycopgFabaceous
I did this as well, after exhausting days and all other options that have been described online. I'm still dumbfounded as to what was preventing it from being installed with pip in venv. I was able to install outside of the virtual environment, no problem. I then literally copied that file from my Python package library directory and pasted within the same within the venv. My hunch is that, becuase my version(s) of Python are Anaconda distributions, that there was something amiss with the path that was being assumed/used.Lianne
A
5

Besides installing the required packages, I also needed to manually add PostgreSQL bin directory to PATH.
$vi ~/.bash_profile
Add PATH=/usr/pgsql-9.2/bin:$PATH before export PATH.
$source ~/.bash_profile
$pip install psycopg2

Allegorist answered 30/3, 2013 at 9:51 Comment(2)
Any idea why this doesn't end up in the default path?Nitwit
I got a error like that how to rectify thisplease help me!!! Command "/usr/bin/python -c "import setuptools, tokenize;__file__='/private/tmp/pip-build-AUbwwG/psycopg2/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-44Va05-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-build-AUbwwG/psycopg2Dietary
U
4

Psycopg2 Depends on Postgres Libraries. On Ubuntu You can use:

apt-get install libpq-dev

Then:

pip install psycopg2
Unpeg answered 23/6, 2015 at 6:55 Comment(1)
It's not a good practice to mix pip packages and apt-get packages.Moonraker
O
4

For MacOS,

Use the below command to install psycopg2, works like charm!!!

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
Offish answered 25/9, 2020 at 6:51 Comment(0)
M
3

On windows XP you get this error if postgres is not installed ...

Maidenly answered 14/3, 2012 at 12:42 Comment(2)
are you sure that is right? I installed postgres on my windows machine and I still get that. ?Photogene
Why don't they have that on their site as pre-req to have postgres?Photogene
A
3

I installed Postgresql92 using the RedHat / CentOS repository on PG's downloads site http://www.postgresql.org/download/linux/redhat/

To get pg_config, I had to add /usr/pgsql-9.2/bin to PATH.

Alternate answered 27/9, 2013 at 15:24 Comment(0)
A
3

On Fedora 24: For Python 3.x

sudo dnf install postgresql-devel python3-devel

sudo dnf install redhat-rpm-config

Activate your Virtual Environment:

pip install psycopg2
Affectionate answered 11/10, 2016 at 2:9 Comment(0)
E
2

I've been battling with this for days, and have finally figured out how to get the "pip install psycopg2" command to run in a virtualenv in Windows (running Cygwin).

I was hitting the "pg_config executable not found." error, but I had already downloaded and installed postgres in Windows. It installed in Cygwin as well; running "which pg_config" in Cygwin gave "/usr/bin/pg_config", and running "pg_config" gave sane output -- however the version installed with Cygwin is:

VERSION = PostgreSQL 8.2.11

This won't work with the current version of psycopg2, which appears to require at least 9.1. When I added "c:\Program Files\PostgreSQL\9.2\bin" to my Windows path, the Cygwin pip installer was able to find the correct version of PostgreSQL, and I was able to successfully install the module using pip. (This is probably preferable to using the Cygwin version of PostgreSQL anyway, as the native version will run much quicker).

Enclasp answered 26/9, 2012 at 3:31 Comment(0)
B
2

On OpenSUSE 13.2, this fixed it:

sudo zypper in postgresql-devel 
Byyourleave answered 1/7, 2015 at 18:19 Comment(0)
E
2

FOR FEDORA USERS:

libpq-dev is one of the dependencies, however, this is how the package should be named in the installation: libpq-devel

So this should solve the problem for Fedora:

sudo yum install libpq-devel
Eyestalk answered 25/7, 2022 at 9:12 Comment(0)
E
1

For lowly Windows users were stuck having to install psycopg2 from the link below, just install it to whatever Python installation you have setup. It will place the folder named "psycopg2" in the site-packages folder of your python installation.

After that, just copy that folder to the site-packages directory of your virtualenv and you will have no problems.

here is the link you can find the executable to install psycopg2

http://www.lfd.uci.edu/~gohlke/pythonlibs/

Erlin answered 21/12, 2014 at 21:33 Comment(1)
i tried this and i get psycopg2-2.6-cp34-none-win_amd64.whl is not a supported wheel on this platform.Balbinder
I
1

On Ubuntu I just needed the postgres dev package:

sudo apt-get install postgresql-server-dev-all

*Tested in a virtualenv

Invert answered 4/1, 2016 at 14:47 Comment(0)
S
1

I could install it in a windows machine and using Anaconda/Spyder with python 2.7 through the following commands:

 !pip install psycopg2

Then to establish the connection to the database:

 import psycopg2
 conn = psycopg2.connect(dbname='dbname',host='host_name',port='port_number', user='user_name', password='password')
Studhorse answered 11/4, 2016 at 8:52 Comment(1)
I got this working with database listed in psql -l, host localhost, default database port 5432, user listed with \du once you get into psql and guessing the password.Ani
P
1

In Arch base distributions:

sudo pacman -S python-psycopg2
pip2 install psycopg2  # Use pip or pip3 to python3
Pelham answered 9/7, 2016 at 9:29 Comment(0)
I
1

On OSX 10.11.6 (El Capitan)

brew install postgresql
PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2
Intradermal answered 24/2, 2017 at 23:35 Comment(2)
On OSX 10.12.3 (Sierra): brew install postgresql PATH=$PATH:/usr/local/Cellar/postgresql/9.6.2/bin/ pip install psycopg2Untoward
On OS X 10.14, this tuned out to be very challenging. See detailed solution here: https://mcmap.net/q/64541/-linking-not-working-in-homebrew-39-s-cmake-since-mojaveDandle
B
1

On OSX with macports:

sudo port install postgresql96
export PATH=/opt/local/lib/postgresql96/bin:$PATH
Burl answered 17/3, 2017 at 14:7 Comment(0)
T
1

if pip is not working than you can download .whl file from here https://pypi.python.org/pypi/psycopg2 extract it.. than python setup.py install

Towrope answered 23/1, 2018 at 12:21 Comment(0)
N
1

I was having this problem, the main reason was with 2 equal versions installed. One by postgres.app and one by HomeBrew.

If you choose to keep only the APP:

brew unlink postgresql
pip3 install psycopg2
Niobic answered 10/7, 2019 at 20:48 Comment(0)
A
1

Installation on MacOS

Following are the steps, which worked for me and my team members while installing psycopg2 on Mac OS Big Sur and which we have extensively tested for Big Sur. Before starting make sure you have the Xcode command-line tool installed. If not, then install it from the Apple Developer site. The below steps assume you have homebrew installed. If you have not installed homebrew then install it. Last but not the least, it also assumes you already have PostgreSQL installed in your system, if not then install it. Different people have different preferences but the default installation method on the official PostgreSQL site via Enterprise DB installer is the best method for the majority of people.

  • Put up the linkage to pg_config file in your .zshrc file by:
    export PATH="$PATH:/Library/PostgreSQL/12/bin:$PATH". This way you are having linkage with the pg_config file in the /Library/PostgreSQL/12/bin folder. So if your PostgreSQL installation is via other means, like Postgres.app or Postgres installation via homebrew, then you need to have in your .zshrc file the link to pg_config file from the bin folder of that PostgreSQL installation as psycopg2 relies on that.

  • Install OpenSSL via Homebrew using the command brew install openssl. The reason for this is that libpq, the library which is the basis of psycopg2, uses openssl - psycopg2 doesn't use it directly. After installing put the following commands in your .zshrc file:

    • export PATH="/usr/local/opt/[email protected]/bin:$PATH"
    • export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
    • export CPPFLAGS="-I/usr/local/opt/[email protected]/include"
      By doing this you are creating necessary linkages in your directory. These commands are suggested by brew while you install openssl and have been directly picked up from there.
  • Now comes the most important step, which is to install libpq using the command brew install libpq. This installs libpq library. As per the documentation

libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.

  • Link libpq using brew link libpq, if this doesn't work then use the command: brew link libpq --force.
  • Also put in your .zshrc file the following
    export PATH="/usr/local/opt/libpq/bin:$PATH". This creates all the necessary linkages for libpq library .
  • Now restart the terminal or use the following command source ~/.zshrc.

    This works even when you are working in conda environment.

    N.B. pip install psycopg2-binaryshould be avoided because as per the developers of the psycopg2 library

The use of the -binary packages in production is discouraged because in the past they proved unreliable in multithread environments. This might have been fixed in more recent versions but I have never managed to reproduce the failure.

Amory answered 30/5, 2021 at 2:10 Comment(0)
H
1

On Debian Bookworm with python3 the command that worked for me was,

sudo apt-get install python3-psycopg2

According to the comments during the install, it makes psycopg2 available across the entire machine.

Hoenack answered 1/12, 2023 at 10:15 Comment(0)
S
0

On macOS Mojave make sure you on newest update with Command Line Tools 10.3 - that worked for me - updated it with Software Update, previous version of Command Line Tools on Mojave did not work for me.

Safko answered 23/7, 2019 at 16:11 Comment(0)
A
0

Make sure Postgres is installed and PATH is updated before running pip install psycopg2

export PATH="$PATH:/Applications/Postgres.app/Contents/Versions/12/bin"
Aurora answered 25/7, 2020 at 12:25 Comment(0)
C
0

Every time I run into this problem this seems to work for me.

pip install psycopg2==2.7.5
Crumple answered 22/8, 2020 at 22:56 Comment(0)
P
0

I had this error only with Python2. Immediately I upgraded my virtual environment to Python3.8, the error was no more.

Prohibition answered 10/6, 2021 at 16:44 Comment(0)
B
-3

On windows this is how it works
On the command prompt after installing flask via pip in virtual environment, run this command

>pip install psycopg2

Check this

Bistort answered 29/8, 2019 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.