在Postgres PL / Python中加载dll库的正确方法是什么? [英] What is the correct way to load a dll library in Postgres PL/Python?

查看:111
本文介绍了在Postgres PL / Python中加载dll库的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下给出错误

drop function testing();
CREATE FUNCTION testing()
 RETURNS text
AS $$
import ctypes
try:
   ctypes.windll.LoadLibrary("D:\\jcc.dll")
except:
   import traceback
   plpy.error(traceback.format_exc())
return ''
$$ LANGUAGE plpythonu;
select testing();

错误消息:

ERROR:  ('Traceback (most recent call last):\n  File "<string>", line 5, in __plpython_procedure_testing_1517640\n  File "D:\\Python26\\Lib\\ctypes\\__init__.py", line 431, in LoadLibrary\n    return self._dlltype(name)\n  File "D:\\Python26\\Lib\\ctypes\\__init__.py", line 353, in __init__\n    self._handle = _dlopen(self._name, mode)\nWindowsError: [Error 126] The specified module could not be found\n',)

在python解释器中工作正常。

It works fine in a python interpretor.

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.windll.LoadLibrary("D:\\jcc.dll")
<WinDLL 'D:\jcc.dll', handle 410000 at 1d9cb10>
>>>


推荐答案

找不到指定的模块 Windows发出的那些有用的错误消息中,并不总是意味着您的意思。

"The specified module could not be found" is one of those helpful error messages Windows emits that doesn't always mean what you think it means.

如果您尝试加载的DLL,Windows将产生该消息。找不到依赖的任何

由于PostgreSQL以其自己的用户帐户运行,因此其路径与解释器在运行时所使用的路径不同。您正在测试。如果 jcc.dll 取决于(例如) c:\jccsupportfiles\aaa.dll c:\jccsupportfiles 在您的PATH上,而不在Pg服务器的PATH上,这可以解释您的问题。

Since PostgreSQL runs in its own user account it has a different PATH to that which your interpreter runs in when you're testing. If jcc.dll depends on (say) c:\jccsupportfiles\aaa.dll and c:\jccsupportfiles is on your PATH but not the Pg server's PATH, that would explain your problem.

尝试使用 Dependency Walker(depends.exe)来确定您的DLL需要哪些DLL,以及它们在哪里。

Try using Dependency Walker (depends.exe) to determine which DLLs your DLL requires and where they are. See if it's a PATH issue.

与其混淆Pg服务器的PATH,不如将jcc.dll所需的所有DLL放在与jcc.dll相同的目录中。 。当尝试加载依赖的模块时,IIRC Windows将始终与它首先加载的模块位于同一目录中。

Rather than messing with the Pg server's PATH, consider just putting all the DLLs required by jcc.dll in the same directory as jcc.dll. IIRC Windows will always look in the same directory as the module it's loading first when it tries to load a module it depends on.

这篇关于在Postgres PL / Python中加载dll库的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆