3

I have downloaded the latest build of pyscopg2 and have tried to build and install it using the directions provided. However i always get an error saying that 'w' is undeclared. Does anybody have any experience with this?

zpesk
  • 4,343
  • 7
  • 39
  • 61

3 Answers3

11

This is an error that crops up when the build tools cannot find your Postgresql libraries. It means one of three things:

  1. You don't have postgresql installed on your system. If so, download and build postgres, or download a pre-built psycopg2 binary for OS X.

  2. You have postgresql installed on your system, but you installed from a binary package and therefore don't have the necessary libraries that psycopg2 needs. In this case, download and build postgres.

  3. More commonly, though, this means that you have built postgres on your system and just need to instruct psycopg2 how to find the pg_config binary so that it can configure the compilation. Either:

    a. put the path to pg_config in your shell path (it's usually at /usr/local/pgsql/bin/ if you built postgres from source using the defaults.

    b. or, edit the setup.cfg file in the psycopg2 source folder and provide the full path to pg_config on the line that starts with pg_config=. Be sure to uncomment this line by removing the hash symbol at the front. If you built postgres using the defaults, the line will look something like:

    pg_config=/usr/local/pgsql/bin/pg_config

Jarret Hardie
  • 95,172
  • 10
  • 132
  • 126
  • 2
    If you install PostgreSQL 9.0.2 on Snow Leopard via the One Click Installer (http://www.postgresql.org/download/macosx), you'll have to edit psycopg2's `setup.cfg` like so: `pg_config=/Library/PostgreSQL/9.0/bin/pg_config`. – Dave Jan 08 '11 at 19:35
3

using MacPorts on Snow Leopard

pg_config=/opt/local/lib/postgresql90/bin/pg_config
siznax
  • 474
  • 5
  • 7
  • 3
    Thank you! It helped me to find it. Finally, I've used command: ``PATH=$PATH:/opt/local/lib/postgresql90/bin/ pip install psycopg2`` – rudyryk Mar 10 '12 at 19:27
0

I needed to install the psycopg2 library only in a virtualenv without adding it to the root python and I didn't want to fully install postgreSQL on my local machine so I came up with this solution which seems to work really well.

  1. Download the postgres.app from here, and drop the app in the Applications folder.

  2. In a shell, add the postgres.app bin directory to the PATH:

export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin

  1. Activate the virtualenv:

. myvenv/bin/activate

  1. pip install psycopg2

I tried setting the pg_config variable but that didn't work. The pip install specifically told me that I had to put the directory where pg_config was located in the path.

I also kinda prefer this solution because, if I want to run PostgreSQL locally, I can easily just start up the app and then close it when I'm done and it's gone -- nothing left running in the background. No system config changes or anything. It is a great way to run PostgreSQL for local development or a quick demo.

ThatAintWorking
  • 1,330
  • 20
  • 32