如何在 PostgreSQL 9.3 x64 Windows 7 上安装 PL/Python?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24216627/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:29:44  来源:igfitidea点击:

How to install PL/Python on PostgreSQL 9.3 x64 Windows 7?

pythonpostgresqlwindows-7-x64postgresql-9.3plpython

提问by Tiago Stapenhorst Martins

I have tried to install the PL/Python v2.x language inside PostgreSQL on my database running the query:

我尝试在运行查询的数据库上的 PostgreSQL 内安装 PL/Python v2.x 语言:

CREATE EXTENSION plpythonu;

(I got this from http://www.postgresql.org/docs/9.3/static/plpython.html)

(我从http://www.postgresql.org/docs/9.3/static/plpython.html得到这个)

But I'm getting this error:

但我收到此错误:

ERRO:  n?o p?de acessar arquivo "$libdir/plpython2": No such file or directory
********** Error **********
ERRO: n?o p?de acessar arquivo "$libdir/plpython2": No such file or directory
SQL state: 58P01

How to install this in an automated way? I need to install it on many computers.

如何以自动方式安装它?我需要在许多计算机上安装它。

回答by Craig Ringer

Typically this error message is a misleading one emitted by the Windows API LoadLibrarycall. What it actually means is closer to:

通常,此错误消息是由 Windows APILoadLibrary调用发出的误导性消息。它的实际含义更接近于:

Error when loading plpython2.dll: Cannot find dependency DLL python27.dllon PATH

错误时加载plpython2.dll:找不到依赖的DLLpython27.dllPATH

but instead Windows just acts like it is plpython2.dllits self that could not be loaded.

但是 Windows 只是表现得好像它plpython2.dll自己无法加载一样。

You can tell if this is the issue by checking the libdirectory of your PostgreSQL install for a plpython2.dll. If it's there, but you get this error, then it's a missing Python runtime. If there's no plpython2.dllat all then your PostgreSQL install is missing plpython2, something I'm raising with the packaging team.

您可以通过检查libPostgreSQL 安装目录中的plpython2.dll. 如果它在那里,但你得到这个错误,那么它是一个缺少的 Python 运行时。如果根本没有plpython2.dll,那么您的 PostgreSQL 安装缺少 plpython2,这是我与打包团队提出的

If you have plpython2.dllbut it won't load, you need to install the Python runtime that matches the PostgreSQL version. It must be the same Python major version as was used to compile PostgreSQL, e.g. if Python 2.7 was used to compile PostgreSQL, Python 2.6 won't work to run plpython.

如果有plpython2.dll但无法加载,则需要安装与 PostgreSQL 版本匹配的 Python 运行时。它必须与用于编译 PostgreSQL 的 Python 主要版本相同,例如,如果使用 Python 2.7 编译 PostgreSQL,则 Python 2.6 将无法运行 plpython。

It'd be nice if installing the required runtime was automated via the installer, but at present it isn't. It's also not properly documented, which I'll take up with the packaging teamThe correct runtime to install is now documented in doc\installation-notes.htmlinside the install directory, which you can also get to via PostgresSQL 9.3 -> Documentation -> Installation Notesin the Start menu.

如果通过安装程序自动安装所需的运行时会很好,但目前还不是。它也没有正确记录,我将与打包团队一起处理要安装的正确运行时现在记录在doc\installation-notes.html安装目录中,您也可以通过开始菜单中的PostgresSQL 9.3 -> 文档 -> 安装说明.

For older relases that lack this information in their "installation notes" file, if you're not sure what version of Python is required you can use depends.exe(dependency walker)to see which Python DLL it's linked to. You need the same architecture of Python too - if you're installing 64-bit PostgreSQL you need 64-bit Python, etc.

对于在“安装说明”文件中缺少此信息的旧版本,如果您不确定需要哪个版本的 Python,您可以使用depends.exe(dependency walker)查看它链接到哪个 Python DLL。您也需要相同的 Python 架构——如果您要安装 64 位 PostgreSQL,则需要 64 位 Python,等等。

The PostgreSQL 9.3 packages require Python 27. So go download Python 2.7 from http://python.org/(not ActiveState, they aren't necessarily compatible). Make sure Python is added to the PATHby the installer (it's an option when you run the installer). Then re-try after re-starting PostgreSQL.

PostgreSQL 9.3 包需要 Python 27。所以从http://python.org/下载 Python 2.7 (不是 ActiveState,它们不一定兼容)。确保PATH安装程序将 Python 添加到 中(这是运行安装程序时的一个选项)。然后重新启动PostgreSQL后重试。

You can automate installation of Python with:

您可以使用以下命令自动安装 Python:

start /wait msiexec /i python-2.7.3.amd64.msi /qb /passive TARGETDIR=%SystemDrive%\Python27_x64 ALLUSERS=1

where python-2.7.3.amd64.msiis the filename of the Python binary you installed, and you're installing the 64-bit version to C:\Python27_x64. Adjust as desired.

python-2.7.3.amd64.msi您安装的 Python 二进制文件的文件名在哪里,并且您正在将 64 位版本安装到C:\Python27_x64. 根据需要进行调整。

回答by fgiron

In my case it worked just installing Python 3.3. Previously I had 2.7 and 3.4, but non of them was the want it wanted.

在我的情况下,它只安装 Python 3.3 就可以工作。以前我有 2.7 和 3.4,但它们都不是它想要的。

I have PostgreSQL 9.4 x64 running on Windows 7

我在 Windows 7 上运行 PostgreSQL 9.4 x64