postgresql postgres 和 python

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

postgres and python

pythonpostgresqlplpython

提问by Jim

In postgres 9.2 I am trying to create a python program that can be a trigger. I want to run an external program (an exe on the local disk) so I am using python to run it. When I try to create a simple program like this:

在 postgres 9.2 中,我试图创建一个可以作为触发器的 python 程序。我想运行一个外部程序(本地磁盘上的一个exe),所以我使用python来运行它。当我尝试创建一个像这样的简单程序时:

CREATE FUNCTION one ()
RETURNS int
AS $$
# PL/Python function body
$$ LANGUAGE plpythonu;

I get the error:

我收到错误:

ERROR:  language "plpythonu" does not exist
HINT:  Use CREATE LANGUAGE to load the language into the database.

When I run:

当我运行时:

CREATE LANGUAGE plpythonu

I get the error:

我收到错误:

ERROR:  could not access file "$libdir/plpython2": No such file or directory

I am using Windows 7 and python 2.5 .

我正在使用 Windows 7 和 python 2.5 。

I have looked in many places but cannot find a solution.

我找了很多地方,但找不到解决方案。

Any ideas?

有任何想法吗?

采纳答案by Craig Ringer

To resolve this for plpython3, it was necessary to:

要为 plpython3 解决这个问题,有必要:

  • Install Python 3.2
  • Run CREATE LANGUAGE plpython3u
  • 安装 Python 3.2
  • CREATE LANGUAGE plpython3u

Update: I've written a much better explanation here: https://stackoverflow.com/a/24218449/398670

更新:我在这里写了一个更好的解释:https: //stackoverflow.com/a/24218449/398670

回答by Raghavendra Kumar

I have just solved this problem, literally a few days back. The solution is quite involved. Here it goes.

几天前,我刚刚解决了这个问题。解决方案相当复杂。就到这里了。

  1. Install python 3.2.* version only on your system.
  2. In Postgresql use the 'CREATE LANGUAGE plpython3u' command to install Python 3 language support. More often than not, it will give the following error "unable to load ".....\plpython3.dll" error 126. (Note if it installs correctly, no error will be displayed.)

  3. In case you get the above error, goto your python installation directory (default is C:\python32) and look for "python3.dll" in the DLL's folder. Copy this file to your Postgresql 'lib' folder in the installation directory of Postgres (default is c:\program files\postgres\9.x\lib\"). Rename this copied file to python32.dll.

  4. Now run the 'CREATE LANGUAGE plpython3u' command again. It should work this time.

  1. 仅在您的系统上安装 python 3.2.* 版本。
  2. 在 Postgresql 中,使用“CREATE LANGUAGE plpython3u”命令来安装 Python 3 语言支持。通常情况下,它会给出以下错误“无法加载“.....\plpython3.dll”错误 126。(请注意,如果安装正确,则不会显示任何错误。)

  3. 如果您遇到上述错误,请转到您的 python 安装目录(默认为 C:\python32)并在 DLL 的文件夹中查找“python3.dll”。将此文件复制到 Postgres 安装目录中的 Postgresql 'lib' 文件夹中(默认为 c:\program files\postgres\9.x\lib\")。将此复制的文件重命名为 python32.dll。

  4. 现在再次运行“CREATE LANGUAGE plpython3u”命令。这次应该可以了。

To verify, check out the pg_available_extensions view in the system tables of postgresql. The row containing plpython3u should have a version number in the 'installed version' column.

要验证,请查看 postgresql 系统表中的 pg_available_extensions 视图。包含 plpython3u 的行应该在“已安装版本”列中有一个版本号。

Note : This only works for plpython3u language. I do not know any similar process for plpython2u.

注意:这仅适用于 plpython3u 语言。我不知道 plpython2u 有任何类似的过程。

回答by jlujan

Postgres uses the ActiveState distros of Python. Most likely, your 2.5 is too outdated and Postgres cant load the plpython dll or didn't install it because there was no suitable python. I think recent postgres is buil6 against Python3 not 2.x. You can look in the postgres lib directory for plpython3.dll to find out what you need.

Postgres 使用 Python 的 ActiveState 发行版。最有可能的是,你的 2.5 太过时了,Postgres 无法加载 plpython dll 或者没有安装它,因为没有合适的 python。我认为最近的 postgres 是针对 Python3 而不是 2.x 的 buil6。您可以在 postgres lib 目录中查找 plpython3.dll 以找出您需要的内容。

回答by user3700545

I'm installed python 3.2(x64) y postgres 9.3 (x64)

我安装了 python 3.2(x64) y postgres 9.3 (x64)

Execute this code CREATE EXTENSION plpython3u

执行这段代码 CREATE EXTENSION plpython3u

Do not forget to check the "installation-note.html" your version of postgresSQL there are specific python version for your postgresSQL

不要忘记检查“installation-note.html”你的 postgresSQL 版本,你的 postgresSQL 有特定的 python 版本