为什么我不能安装psycopg2? (Python 2.6.4,PostgreSQL 8.4,OS X 10.6.3)

时间:2020-12-26 21:01:28

ORIGINAL MESSAGE (now outdated):

原始消息(现已过时):

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

运行python setup.py install后,我得到以下内容:

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.

对于那些知道关于后端网络编程的第一件事情的人来说,可能会有一些令人惊讶的显而易见的事情,但不幸的是,这对我来说都是一种愚蠢的行为。 psycopg2文档没有帮助。


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

6月12日早期更新:更新我的所有软件后,错误消息已更改。

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

现在,当我运行“python setup.py install”时,我得到以下内容:

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:

当我将“gcc-4.0”放入终端时,它可能会或可能不相关,它会返回:

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:

更新格林威治标准时间12月12日12:41:我认为macports安装有效,但当我尝试运行网站时,它结束时出现以下错误:

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.

所以我想这意味着psycopg2毕竟没有正确安装。所以我回到原点。

5 个解决方案

#1


3  

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:

我认为你让它变得更难。我建议不要直接运行setup.py,而是让MacPorts为您完成:

sudo port install py26-psycopg2

sudo port安装py26-psycopg2

#2


8  

(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.

您的计算机或版本上没有“gcc4.0”编译器可执行文件,或者安装在python无法找到/使​​用的位置。 XCode / Developer Tools(包括GCC)应该在您的原始OSX安装DVD上。

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.

既然你很谦虚地称自己为新手,这里有一个智慧的核心......解决这个错误实际上与后端Web开发没有任何关系,因为它是你的本地开发环境(你的机器和所有软件都是如此)它是配置和安装)这是问题。我这样解读gobbledegook的最佳提示就是开始使用谷歌搜索关键字来解决之前从未听过的事情。如果我在你的鞋子里,这个错误信息让我尖叫“去找出gcc4.0到底是什么。然后,当我知道它是什么以及它做了什么,以及为什么python需要它,那我就弄清楚为什么python在我的电脑上找不到它,然后我就它做了些什么。“然而,解决这些问题的满足感并非适用于所有人,这是肯定的。

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.

所有这些问题的答案是:psycopg2是一个用C语言编写的python扩展。 python的很多扩展都是用C语言编写的,而不是python,因为C比python更加优化。实际上,这就是python解释器本身所写的内容。 C语言代码必须在可用之前进行编译(与python代码不同,这是解释的),在这种情况下,您需要的编译器是gcc4.0。现在,也许如果您使用的是Windows或Linux,psycopg2的编译版本可能已经可用,并且您不需要安装GCC,因为您不必编译它来使用它(它将被编译为您)。但是,似乎你必须自己在OS X上编译它,为此,你需要程序“gcc4.0”在系统PATH中可用,这样你试图运行的安装脚本就可以找到并使用它。在OS X上,您可以从计算机附带的原始安装DVD中获取它。将它们弹出驱动器并找到Developer Tools安装程序。一旦安装完成后,您就可以通过尝试在任何控制台窗口中运行命令“gcc4.0”来检查是否安装了GCC 4.0编译器,并查看它是否已安装并位于您的路径中。

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:

看起来你现在已经很好地安装了GCC 4.0编译器!干得好。当你看到这个:

>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.

那个输出是编译器告诉你它的确切版本,然后告诉你你没有给它任何参数,所以,它不会为你做任何事情。哪个没关系,因为你的psycopg2安装脚本会调用它,而不是直接调用它。

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:

接下来,看起来像psycopg2预计你应该安装PostgreSQL服务器开发库。由于我发现您现在正在使用MacPorts,因此您应该可以使用此命令轻松安装这些库:

sudo port install postgresql-server-devel

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

这应该可以让你找到设备正在寻找的pg_config可执行文件。

Keep us updated on your progress!

让我们了解您的进度!

#3


4  

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

如果您已经从Enterprise DB安装了postgres,那么您可能只是想要

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:

然后它不喜欢你的新gcc - 你可以覆盖你的gcc强制它使用gcc4.0:

alias gcc=/usr/bin/gcc-4.0

and then re-running your easy_install again.

然后再次重新运行easy_install。

#4


2  

I am sure that we would all hate to overlook the "screamingly obvious", so perhaps it is worth a check before going and installing a new compiler. In this case it could be that PostgreSQL is not installed on the person's Mac. Hence psycopg2 cannot find the 'pg_config' program that comes with newer versions of that database, causing the warning-message "Unable to find 'pg_config'" to be emitted.

我相信我们都会讨厌忽视“令人惊讶的明显”,所以在开始安装新的编译器之前,或许值得检查一下。在这种情况下,可能是PostgreSQL没有安装在人的Mac上。因此psycopg2找不到该数据库的较新版本附带的'pg_config'程序,导致发出警告消息“无法找到'pg_config'”。

So, before fiddling with a new compiler or any other part of the Developer toolchain, first check and see if you have PostgreSQL installed. If you do then find the 'pg_config' program, and set that path in the 'setup.cfg' file in the psycopg distribution. Then run 'python setup.py install' and see if you get the same error messages. Hopefully, it just starts "compiling"; but if it doesn't then you would be justified in executing the more difficult procedures described above.

因此,在使用新的编译器或开发人员工具链的任何其他部分之前,首先检查并查看是否安装了PostgreSQL。如果你这样做,那么找到'pg_config'程序,并在psycopg发行版的'setup.cfg'文件中设置该路径。然后运行'python setup.py install'并查看是否收到相同的错误消息。希望它只是开始“编译”;但如果没有,那么你将有理由执行上述更困难的程序。

#5


2  

  1. Install PostgreSQL for Mac - http://www.postgresql.org/download/macosx

    安装PostgreSQL for Mac - http://www.postgresql.org/download/macosx

  2. set the path to the new PostgreSQL location for psycopg2 install:

    为psycopg2 install设置新PostgreSQL位置的路径:

PATH=$PATH:/Library/PostgreSQL/9.0/bin/ sudo easy_install psycopg2

#1


3  

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:

我认为你让它变得更难。我建议不要直接运行setup.py,而是让MacPorts为您完成:

sudo port install py26-psycopg2

sudo port安装py26-psycopg2

#2


8  

(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.

您的计算机或版本上没有“gcc4.0”编译器可执行文件,或者安装在python无法找到/使​​用的位置。 XCode / Developer Tools(包括GCC)应该在您的原始OSX安装DVD上。

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.

既然你很谦虚地称自己为新手,这里有一个智慧的核心......解决这个错误实际上与后端Web开发没有任何关系,因为它是你的本地开发环境(你的机器和所有软件都是如此)它是配置和安装)这是问题。我这样解读gobbledegook的最佳提示就是开始使用谷歌搜索关键字来解决之前从未听过的事情。如果我在你的鞋子里,这个错误信息让我尖叫“去找出gcc4.0到底是什么。然后,当我知道它是什么以及它做了什么,以及为什么python需要它,那我就弄清楚为什么python在我的电脑上找不到它,然后我就它做了些什么。“然而,解决这些问题的满足感并非适用于所有人,这是肯定的。

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.

所有这些问题的答案是:psycopg2是一个用C语言编写的python扩展。 python的很多扩展都是用C语言编写的,而不是python,因为C比python更加优化。实际上,这就是python解释器本身所写的内容。 C语言代码必须在可用之前进行编译(与python代码不同,这是解释的),在这种情况下,您需要的编译器是gcc4.0。现在,也许如果您使用的是Windows或Linux,psycopg2的编译版本可能已经可用,并且您不需要安装GCC,因为您不必编译它来使用它(它将被编译为您)。但是,似乎你必须自己在OS X上编译它,为此,你需要程序“gcc4.0”在系统PATH中可用,这样你试图运行的安装脚本就可以找到并使用它。在OS X上,您可以从计算机附带的原始安装DVD中获取它。将它们弹出驱动器并找到Developer Tools安装程序。一旦安装完成后,您就可以通过尝试在任何控制台窗口中运行命令“gcc4.0”来检查是否安装了GCC 4.0编译器,并查看它是否已安装并位于您的路径中。

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:

看起来你现在已经很好地安装了GCC 4.0编译器!干得好。当你看到这个:

>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.

那个输出是编译器告诉你它的确切版本,然后告诉你你没有给它任何参数,所以,它不会为你做任何事情。哪个没关系,因为你的psycopg2安装脚本会调用它,而不是直接调用它。

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:

接下来,看起来像psycopg2预计你应该安装PostgreSQL服务器开发库。由于我发现您现在正在使用MacPorts,因此您应该可以使用此命令轻松安装这些库:

sudo port install postgresql-server-devel

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

这应该可以让你找到设备正在寻找的pg_config可执行文件。

Keep us updated on your progress!

让我们了解您的进度!

#3


4  

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

如果您已经从Enterprise DB安装了postgres,那么您可能只是想要

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:

然后它不喜欢你的新gcc - 你可以覆盖你的gcc强制它使用gcc4.0:

alias gcc=/usr/bin/gcc-4.0

and then re-running your easy_install again.

然后再次重新运行easy_install。

#4


2  

I am sure that we would all hate to overlook the "screamingly obvious", so perhaps it is worth a check before going and installing a new compiler. In this case it could be that PostgreSQL is not installed on the person's Mac. Hence psycopg2 cannot find the 'pg_config' program that comes with newer versions of that database, causing the warning-message "Unable to find 'pg_config'" to be emitted.

我相信我们都会讨厌忽视“令人惊讶的明显”,所以在开始安装新的编译器之前,或许值得检查一下。在这种情况下,可能是PostgreSQL没有安装在人的Mac上。因此psycopg2找不到该数据库的较新版本附带的'pg_config'程序,导致发出警告消息“无法找到'pg_config'”。

So, before fiddling with a new compiler or any other part of the Developer toolchain, first check and see if you have PostgreSQL installed. If you do then find the 'pg_config' program, and set that path in the 'setup.cfg' file in the psycopg distribution. Then run 'python setup.py install' and see if you get the same error messages. Hopefully, it just starts "compiling"; but if it doesn't then you would be justified in executing the more difficult procedures described above.

因此,在使用新的编译器或开发人员工具链的任何其他部分之前,首先检查并查看是否安装了PostgreSQL。如果你这样做,那么找到'pg_config'程序,并在psycopg发行版的'setup.cfg'文件中设置该路径。然后运行'python setup.py install'并查看是否收到相同的错误消息。希望它只是开始“编译”;但如果没有,那么你将有理由执行上述更困难的程序。

#5


2  

  1. Install PostgreSQL for Mac - http://www.postgresql.org/download/macosx

    安装PostgreSQL for Mac - http://www.postgresql.org/download/macosx

  2. set the path to the new PostgreSQL location for psycopg2 install:

    为psycopg2 install设置新PostgreSQL位置的路径:

PATH=$PATH:/Library/PostgreSQL/9.0/bin/ sudo easy_install psycopg2