Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing psycopg2 into virtualenv when PostgreSQL is not installed on development system

Is it possible to install psycopg2 into a virtualenv when PostgreSQL isn't installed on my development system—MacBook Pro with OS X 10.6?

When I run pip install psycopg2 from within my virtualenv, I received the error shown below.

I'm trying to connect to a legacy database on a server using Django, and I'd prefer not to install PostgreSQL on my development system if possible.

Why not install PostgreSQL?

I received an error when installing PostgreSQL using homebrew. I have Xcode4—and only Xcode4—installed on my MacBook Pro and am thinking it's related to missing gcc 4.0. However, this is a problem for another StackOverflow question.

Update 8:37 AM on April 12, 2011: I'd still like to know if this is possible without installing PostgreSQL on my MacBook Pro. However, I ran brew update and forced a reinstallation of ossp-uuid with brew install --force ossp-uuid and now brew install postgresql works. With PostgreSQL successfully installed, I was able to pip install psycopg2 from within my virtualenv.

Error from pip install psycopg2

$ pip install psycopg2 Downloading/unpacking psycopg2   Running setup.py egg_info for package psycopg2      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  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 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 /Users/matthew/.pip/pip.log 

Preliminary Research

Below are the articles I read as preliminary research:

  • Installing psycopg2 to use Django with PostgreSQL on OS X
  • Installing psycopg2 on OS X
  • Using psycopg2 with virtualenv on Ubuntu JauntyLucid
  • Postgres, psycopg2, virtualenv install hints
like image 307
Matthew Rankin Avatar asked Apr 12 '11 01:04

Matthew Rankin


People also ask

Do you need Postgres for psycopg2?

The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements.

Could not find a version that satisfies the requirement psycopg2?

Queries related to “could not find a version that satisfies the requirement psycopg2” You may install a binary package by installing 'psycopg2-binary' from PyPI. If you want to install psycopg2 from source, please install the packages required for the build and try again. PyPI 'psycopg2-binary' package instead.

Does psycopg2 work with Python 3?

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


2 Answers

apt-get install libpq-dev 

helped me on debian squeeze

like image 129
Yevgeniy Shchemelev Avatar answered Oct 20 '22 04:10

Yevgeniy Shchemelev


psycopg depends on pg_config command, and if you don't have it, you can't install psycopg.

If system installation is a problem to you, why don't you try compiling PostgreSQL and including generated bin files in your $PATH? Like:

export PATH=/path/to/compiled/postgresql/bin:"$PATH" pip install psycopg2 
like image 38
Hugo Tavares Avatar answered Oct 20 '22 03:10

Hugo Tavares