Skip to content
Advertisement

Installing psycopg2 in a virtualenv in ubuntu os

I using a virtualenv and I am trying to set up postgresql. I have psycopg2 installed on my system, but it appears that my virtual env does not recognize psycopg2. Is it possible to just copy the system wide psycopg2 files into my django project directory or is this a bad approach to take?

This is the relevant part of my settings.py file in my django project.

JavaScript

When I run python manage.py migrate I get this error:

JavaScript

When I do pip install psycopg2 in my virtual env, I get the following error:

JavaScript

Advertisement

Answer

Based on the combination of your question and one of your comments, it appears that when you ran sudo pip install psycopg2, it was using the system install, as it referred to psycopg2 in /usr/lib/python2.7/dist-packages which is different from the environment from which you’re trying to run Django.

Your permissions error, which is from the Django environment, seems likely to be due to not using sudo (among other things, some C compilation needs to take place, during the psycopg2 install, and so sudo is often required whereas it isn’t with many other packages).

I would recommend you refer to the virtualenv install’s pip binary explicitly when running the sudo command.

i.e.: sudo <virtualenv_root>/bin/pip install psycopg2

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement