为什么我无法安装 psycopg2? (Python 2.6.4、PostgreSQL 8.4、OS X 10.6.3)
原始消息(现已过时):
运行 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
对于任何了解后端 Web 编程第一件事的人来说,可能有一些非常明显的东西,但不幸的是,这就是全部对我来说是冗长的。 psycopg2 文档没有帮助。
6 月 12 日上旬更新:更新我的所有软件后,错误消息已更改。
现在,当我运行“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
后面是一长串其他错误消息。
当我将“gcc-4.0”放入终端时,它可能会或可能不相关,它会返回:
i686-apple-darwin10-gcc-4.0.1: no input files
UPDATE 12:41 GMT 6 月 12 日: 我认为 macports 安装已经工作,但是当我尝试运行一个网站,它以以下错误结束:
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
所以我想这意味着 psycopg2 毕竟没有正确安装。所以我又回到了第一点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
(请参阅下面的编辑来了解更新的问题)
您的计算机上没有“gcc4.0”编译器可执行文件,或者没有正确的版本,或者安装在 python 找不到的位置/使用。 XCode/Developer Tools(包括 GCC)应该位于原始 OSX 安装 DVD 上。
既然你谦虚地称自己是新手,这里有一个智慧的结晶...解决这个错误实际上与后端 Web 开发无关,因为它是你本地的开发环境(你的机器和所有软件)它已配置并安装)这就是问题所在。对于破译像这样的官样文章,我的最佳建议是开始用谷歌搜索关键字来查找您以前从未听说过的东西。如果我站在你的立场上,这个错误消息会告诉我“去看看 gcc4.0 到底是什么。然后,当我知道它是什么、它的作用以及为什么 python 需要它时,我就会明白为什么python 在我的计算机上找不到它,然后我对此采取了一些措施。”不过,解决这类问题的满足感并不是每个人都能满足,这是肯定的。
所有这些问题的答案是:psycopg2 是一个用 C 语言编写的 python 扩展。 python 的许多扩展都是用 C 编写的,而不是 python,因为 C 比 python 更加优化。实际上,这就是 python 解释器本身的编写方式。 C 语言代码必须先进行编译才能使用(与 Python 代码不同,Python 代码需要解释),在这种情况下,您需要的编译器是 gcc4.0。现在,也许如果您使用的是 Windows 或 Linux,那么 psycopg2 的编译版本可能已经可用,并且您不需要安装 GCC,因为您不必编译它即可使用它(它已经编译为你)。但是,似乎您必须在 OS X 上自己编译它,为此,您需要在系统 PATH 中提供程序“gcc4.0”,以便您尝试运行的安装脚本可以找到并使用它。在 OS X 上,您可以从计算机附带的原始安装 DVD 中获取它。将它们放入驱动器中并找到开发人员工具安装程序。安装完成后,您应该能够通过尝试在任何控制台窗口中运行命令“gcc4.0”来检查 GCC 4.0 编译器是否已安装,并查看它是否已安装并位于您的路径中。
编辑您的更新
看起来您现在已经很好地安装了 GCC 4.0 编译器!干得好。当您看到以下内容时:
该输出是编译器告诉您其确切版本,然后告诉您您没有给它任何参数,因此,它不会为您做任何事情。这没关系,因为你的 psycopg2 设置脚本将调用它,而不是你直接调用它。
接下来,psycopg2 似乎希望您也应该安装 PostgreSQL 服务器开发库。因为我看到您现在正在使用 MacPorts,所以您应该能够使用以下命令轻松安装这些库:
这应该会为您提供安装程序正在寻找的丢失的
pg_config
可执行文件。让我们随时了解您的进展!
(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:
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:
That should get you your missing
pg_config
executable that the setup is looking for.Keep us updated on your progress!
如果您已经从 Enterprise DB 安装了 postgres,您可能只是想要
或类似的 - 取决于您拥有的版本。
如果它抱怨,
那么它不喜欢你的较新的 gcc - 你可以覆盖你的 gcc 以强制它使用 gcc4.0,方法是:
然后重新运行你的 easy_install 。
If you've installed postgres from Enterprise DB you'll prob just want to
or similar - depending on the version you have.
If it complains about
then it doesn't like your newer gcc - you can overwrite your gcc to force it to use gcc4.0 by doing:
and then re-running your easy_install again.
我认为你让事情变得比原来更难了。我建议不要直接运行 setup.py,而是让 MacPorts 为您执行此操作:
sudo port install py26-psycopg2
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
我确信我们都不愿意忽视“极其明显”的东西,所以在安装新的编译器之前也许值得检查一下。在这种情况下,可能是该人的 Mac 上未安装 PostgreSQL。因此 psycopg2 无法找到该数据库较新版本附带的“pg_config”程序,导致发出警告消息“无法找到“pg_config””。
因此,在摆弄新编译器或开发人员工具链的任何其他部分之前,请首先检查您是否安装了 PostgreSQL。如果您这样做,则找到“pg_config”程序,并在 psycopg 发行版的“setup.cfg”文件中设置该路径。然后运行“python setup.py install”并查看是否收到相同的错误消息。希望它只是开始“编译”;但如果没有,那么您就有理由执行上述更困难的程序。
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.
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.
安装 Mac 版 PostgreSQL - http://www.postgresql.org/download/macosx
设置 psycopg2 安装的新 PostgreSQL 位置的路径:
Install PostgreSQL for Mac - http://www.postgresql.org/download/macosx
set the path to the new PostgreSQL location for psycopg2 install: