views:

1246

answers:

3

ORIGINAL MESSAGE (now outdated):

After running python setup.py install I get the following:

Warning: Unable to find 'pg_config' filebuilding 'psycopg2._psycopg' extension
gcc-4.0 -arch ppc -arch i386 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -   DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.2.1 (dt dec ext pq3)" -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DHAVE_PQPROTOCOL3=1 -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -I. -c psycopg/psycopgmodule.c -o build/temp.macosx-10.3-fat-2.6/psycopg/psycopgmodule.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

There's probably something screamingly obvious there to anyone who knows the first thing about back-end web programming, but unfortunately it's all gobbledegook to me. The psycopg2 documentation was not helpful.


UPDATE early 12 June: After updating all my software, the error message has changed.

Now, when I run "python setup.py install" I get the following:

Warning: Unable to find 'pg_config' filebuilding 'psycopg2._psycopg' extension
gcc-4.0 -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.2.1 (dt dec ext pq3)" -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -DHAVE_PQPROTOCOL3=1 -I/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -I. -c psycopg/psycopgmodule.c -o build/temp.macosx-10.3-fat-2.6/psycopg/psycopgmodule.o

followed by a very long list of other error messages.

It may or may not be relevant that when I put "gcc-4.0" into Terminal, it comes back with:

i686-apple-darwin10-gcc-4.0.1: no input files

UPDATE 12:41 GMT 12 June: I thought the macports installation had worked, but when I tried running a site it ended with the following error:

raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

So I guess that means that psycopg2 hadn't installed properly after all. So I'm back to square one.

+3  A: 

(See edits below for your updated question)

You don't have the "gcc4.0" compiler executable on your machine, or the right version, or installed in a location that python can't find/use. XCode/Developer Tools (which include GCC) should be on your original OSX installation DVDs.

Since you're humble enough to call yourself a newbie, here's a nugget of wisdom... Resolving this error really has nothing to do with back-end web development, as it is your local development environment (your machine and all the software as it is configured and installed) that is the problem. The best tip I have for deciphering gobbledegook like this is to start Googling keywords for things you've never heard of before. If I were in your shoes, this error message screams to me to "go find out what the heck is gcc4.0. Then, when I know what it is and what it does, and why python needs it, then I figure out why python can't find it on my computer, and then I do something about it." The satisfaction of resolving these kinds of issues doesn't happen for everyone, though, that's for certain.

The answer to all those questions is this: psycopg2 is a python extension that is written in the C language. A lot of extensions for python are written in C, not python, since C is much more optimized than python will ever be. That's what the python interpreter itself is written in, actually. C language code has to be compiled before it is usable (unlike python code, which is interpreted) and in this case, the compiler you need is gcc4.0. Now, perhaps if you were using Windows or Linux, the compiled version of psycopg2 might have been available already, and you wouldn't need GCC installed, as you wouldn't have to compile it to use it (it would be compiled already for you). But, it seems you'll have to compile it yourself on OS X, and to do that, you need the program "gcc4.0" to be available in the system PATH so that the setup script you're trying to run can find and use it. On OS X, you can get it from your original installation DVDs that ship with your computer. Pop them in the drive and find the Developer Tools installation program. Once you've got that installed, you should then be able to check if the GCC 4.0 compiler is installed by trying to run the command "gcc4.0" in any console window and see if it installed and in in your path.

Edit for your update

It looks like you now have a good installation of the GCC 4.0 compiler! Good work. When you see this:

>gcc4.0
i686-apple-darwin10-gcc-4.0.1: no input files

That output is compiler telling you its exact version, and then telling you that you gave it no parameters, so, it won't do anything for you. Which is okay, since your psycopg2 setup script is going to call it, not you directly.

Next up, it looks like psycopg2 expects that you should have PostgreSQL server development libraries installed as well. Since I see you're now using MacPorts, you should be able to install these libraries easily with this command:

sudo port install postgresql-server-devel

That should get you your missing pg_config executable that the setup is looking for.

Keep us updated on your progress!

Mike Atlas
Thanks very much for all the advice and general elucidation. I've updated all my software and gcc 4.0 is definitely installed now. But I still can't instal psycopg2. The error message has changed though (see updated question). I will attempt to decipher it via google as you suggest.
Upvotes are a good way to give thanks :) Check out my edit for your update.
Mike Atlas
Upvoted with thanks! I tried installing the PostgreSQL server developer libraries via MacPorts but just ran into more problems: http://stackoverflow.com/questions/3033156/how-do-i-give-macports-privileges
Try running "sudo port install postgresql-server-devel". sudo means "super user do" - meaning you will run Macports with full privileges.
Mike Atlas
Doing that gives me these errors :/ `Error: Target org.macports.build returned: shell command failed``Log for postgresql-devel is at:` `/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_postgresql-devel/main.log``Error: The following dependencies failed to build: postgresql-devel``Error: Status 1 encountered during processing.`
Hmm... what do the contents of that log file (main.log) have? You could paste it on pastebin.org
Mike Atlas
I pasted it here: http://pastebin.org/330190Thanks again for taking an interest despite the many twists and turns this seems to be taking. I feel bad that all I can do in return is give one upvote and (hopefully!) a tick.
Hmm, try 'sudo port install postgresql-devel' (not postgresql-server-devel) perhaps.
Mike Atlas
Just comes back with the same error: `Error: Target org.macports.build returned: shell command failed``Log for postgresql-devel is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_postgresql-devel/main.log``Error: Status 1 encountered during processing.`
And, pastebin of the log file? Have you looked at it? I know this is frustrating, but part of solving these problems involves a bit of ambition ;) I can only help so far though.
Mike Atlas
Er, admittedly I didn't make much of an effort at translating the log file. I'll have another go. Here's the most up-to-date log file by the way: http://pastebin.org/332533.
Hmm, looks like it complained at the end about a missing folder? try running this to create the one it said it couldn't find. `sudo mkdir /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_databases_postgresql-devel/work/pgsql`
Mike Atlas
Also, what happens if you try to run this command: `sudo /usr/bin/gnumake -j2`?
Mike Atlas
unfortunately making that folder didn't seem to make any difference - the log file still mentions pgsql: http://pastebin.org/332757. The command you suggested returns: `gnumake: *** No targets specified and no makefile found. Stop.`
Hmm, since you already ran the port install for py26-psycopg2, maybe you're closer than you think. Have a look at the answer for this... you might be 98% there. http://stackoverflow.com/questions/1383126/django-python-beginner-error-when-executing-python-manage-py-syncdb-psycopg2-n
Mike Atlas
It's resolved now last! (see my last comment on Forest's answer). I still don't know why the non-macports installation of psycopg2 didn't work but thank you for trying to untangle that for me. Your comments certainly encouraged me to press on with trying to figure out all this programming terminology (as I will need to do to complete my next task of installing django evolution).
cheers, and you're welcome.
Mike Atlas
+1  A: 

I think you're making it harder than it has to be. Rather than running setup.py directly, I suggest letting MacPorts do it for you:

sudo port install py26-psycopg2

Forest
Thanks but I tried putting that into Terminal and it came back with "sudo: port: command not found"(even Terminal is pretty new to me...)
Perhaps you need to install MacPorts? http://www.macports.org/install.php
Forest
Er, yes, indeed I did...Thanks very much - MacPorts worked a treat.
Unfortunately it wasn't enough to solve the problem: see "UPDATE 12:41 GMT 12 June" at the bottom of the question.
Is it possible you have more than one Python installation on your machine? Perhaps one where psycopg2 was installed and one where it was not? Can you run python from the Terminal? Once in the python interpreter, can you "import psycopg2" successfully?
Forest
Yes you were right I did have multiple Python installations, some without psycopg2. The macports-installed Python did have psycopg2 but Terminal was not executing that Python by default. Now I've sorted out the mess. Thanks for suggesting MacPorts anyway, it made things much much easier. Once I understood that MacPorts was installing a separate version of Python and where that was located it all made sense.
+1  A: 

If you've installed postgres from Enterprise DB you'll prob just want to

export PATH=$PATH:/Library/PostgreSQL/8.4/bin

or similar - depending on the version you have.

If it complains about

cc1: error: unrecognized command line option "-Wno-long-double"

then it doesn't like your newer gcc - you can overwrite your gcc to force it to use gcc4.0 by doing:

alias gcc=/usr/bin/gcc-4.0

and then re-running your easy_install again.

Damian