为什么我不能安装 psycopg2?(Python 2.6.4、PostgreSQL 8.4、OS X 10.6.3)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3029274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't I install psycopg2? (Python 2.6.4, PostgreSQL 8.4, OS X 10.6.3)
提问by Nicolas Holzapfel
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.
对于任何了解后端 Web 编程的第一件事的人来说,那里可能有一些非常明显的东西,但不幸的是,对我来说,这一切都是狼吞虎咽。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:
格林威治标准时间 6 月 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 毕竟没有正确安装。所以我回到第一个。
回答by Mike Atlas
(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 compiledbefore 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 上自己编译它,为此,您需要在系统 PATH 中提供程序“gcc4.0”,以便您尝试运行的安装脚本可以找到并使用它。在 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!
让我们了解您的最新进展!
回答by Damian
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。
回答by ?s??o?
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 install py26-psycopg2
回答by Joe User
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.
我相信我们都不愿意忽视“非常明显”,所以在开始安装新编译器之前,也许值得检查一下。在这种情况下,可能是该人的 Mac 上未安装 PostgreSQL。因此,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.
因此,在摆弄新编译器或 Developer 工具链的任何其他部分之前,首先检查并查看您是否安装了 PostgreSQL。如果你找到了'pg_config'程序,然后在psycopg发行版的'setup.cfg'文件中设置那个路径。然后运行“python setup.py install”并查看是否收到相同的错误消息。希望它只是开始“编译”;但如果不是,那么您将有理由执行上述更困难的程序。
回答by GBond
Install PostgreSQL for Mac - http://www.postgresql.org/download/macosx
set the path to the new PostgreSQL location for psycopg2 install:
为 Mac 安装 PostgreSQL - http://www.postgresql.org/download/macosx
设置 psycopg2 安装的新 PostgreSQL 位置的路径:
PATH=$PATH:/Library/PostgreSQL/9.0/bin/ sudo easy_install psycopg2
PATH=$PATH:/Library/PostgreSQL/9.0/bin/ sudo easy_install psycopg2