Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I install psycopg2 for Python 3.x?

Tags:

Just started Python a few days ago and I'm using PyCharm to develop a web application with Django. I have libpq-dev python-dev packages already installed, but it's still throwing me the same error:

./psycopg/psycopg.h:30:20: fatal error: Python.h: No such file or directory 

which according to Google is the issue that occurs when python-dev package isn't installed. Note that I'm running the install from within the PyCharm interface for a virtualenv that I created for 3.2 and 3.3 (not sure how to run it from the terminal). Installing outside of the virtualenv still throws the same error, even when I install it from the terminal with setup.py. If I run pip install psycopg2 from the terminal, it succeeds, but it installs for Python 2.7. According to their website, they have support for up to Python 3.2.

like image 795
Lunyx Avatar asked Dec 31 '13 21:12

Lunyx


People also ask

Does psycopg2 work with python3?

The current psycopg2 implementation supports: Python 2 versions from 2.6 to 2.7. Python 3 versions from 3.2 to 3.6.


2 Answers

On Ubuntu you just run this:

sudo apt-get install python3-psycopg2 
like image 134
Frontware Avatar answered Sep 27 '22 21:09

Frontware


Just run this using the terminal:

$ sudo apt-get install python3-dev 

This way, you could use gcc to build the module you're trying to use.

like image 26
Moayad Mardini Avatar answered Sep 27 '22 19:09

Moayad Mardini