How to install psycopg2 with pip on Python?
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 3
sudo apt install libpq-dev python3-dev
You might need to install python3.8-dev
or similar for e.g. Python 3.8.
Python 2
sudo apt install libpq-dev python-dev
If that's not enough, try
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
Building wheel for psycopg2 ... error pip3 install psycopg2?
I solve my problem work for me
basically issue also with python
version I install python version 3.7 by using this command
sudo apt-get install python3.7
then activate environment
source env/bin/activate
Then I install my requirements.txt files by using this command
python3.7 -m pip install requirements.txt
my this error resolved not show me again
Building wheel for psycopg2 … error pip3 install psycopg2?
then show me
ModuleNotFoundError: No module named 'pandas'
then I install using this way
python3.7 -m pip install pandas
When I run python3.7 manage.py runserver
Then show me error is django-rq
/code/data/.local/lib/python3.7/site-packages/django_rq/queues.py", line 132
def get_queue(name='default', default_timeout=None, async=None,
^
I this so async is reserved word now in python then in my package I replace the name of async
to is_async
in whole django-rq/queues.py
when I run project again then show me this error
import xlsxwriter
ModuleNotFoundError: No module named 'xlsxwriter'
Then I fix by this way
python3.7 -m pip install xlsxwriter
Then show me one more error
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Then I fixed using this way
python3.7 -m pip install bs4
Then my project work fine.
I hope my solution is helpful for anyone.
I have require temporarily python3.7 version so I'm not wanted to change their path to python3 .
How to install psycopg2 on Python 3.9 on Windows?
The following will install prebuilt binaries for windows. It's worked for me on 3.9. You can uninstall pipwin after install psycopg2.
pip install pipwin
pipwin install psycopg2
Optional after psycopg2 installed:
pip uninstall pipwin
How to install Psycopg2 for Python 3.5
I ran into a similar issue on Windows. I had to install a compiled version of it and then easy_install it.
You can find a compiled version of psycopg2 here: http://www.lfd.uci.edu/~gohlke/pythonlibs/
And then do easy_install C:/locaiton/of/download.exe
That's what I do to install it on my Windows machine.
Related Topics
Python Unexpected Eof While Parsing
Difference Between Filter and Filter_By in SQLalchemy
How to Find All the Subsets of a Set, with Exactly N Elements
Multiprocessing: Understanding Logic Behind 'Chunksize'
How to Download a File on a Click Event Using Selenium
Get the Second Largest Number in a List in Linear Time
Trying to Mock Datetime.Date.Today(), But Not Working
Iterating Through Directories with Python
How to Use an Image for the Background in Tkinter
How to Get Indices of a Sorted Array in Python
Maximum Value for Long Integer
How to Check If Type of a Variable Is String
How to Get First Element in a List of Tuples