PostgreSQL 9.1: Installing plpythonu/plpython3u (Python) in Windows
2014-03-26 02:18
495 查看
PostgreSQL 9.1: Installing plpythonu/plpython3u (Python) in Windows
Install plpython3u
If you're lucky, the following command will just work, and the Python language has been successfully installed:Select All
1
CREATE EXTENSION plpython3u;
If you encounter the following error:
Select All
1
ERROR: could not load library "C:/Program Files/PostgreSQL/9.1/lib/plpython3.dll": The specified module could not be found.
We have a little more work to do.
PostgreSQL 9.1 requires a VERY specific sub-version of the Python DLL: Python 3.2.x. (available here) Any
other version (3.1.x, 3.3.x, or otherwise) will cause the installation of plpython3u to fail. In addition, PostgreSQL 9.1 unfortunately does not appear to ship with Python 2.x support either.
If Python 3.2.x is not installed, download and install it.
Browse to your Python 3.2.x installation directory. By default, this should be something similar to: C:\Python32. From here, navigate to the DDLs directory and locate a DLL named python3.dll.
In a separate window, browse to you PostgreSQL installation directory. By default, this should be something similar to: C:\Program Files\PostgreSQL\9.1. From there, navigate into the lib directory and copy the python3.dll
from the other window into this directory. Rename the copied DLL from python3.dll topython32.dll.
Finally, attempt to run the CREATE EXTENSION command again:
Select All
1
CREATE EXTENSION plpython3u;
This time, you should receive the expected result; signalling the installation was successful.
Select All
1
CREATE EXTENSION
Testing Your plpython3u Extension
First, we need a stored procedure which utilizes the Python language:Select All
12
3
4
5
6
7
DROP FUNCTION test_fn(a integer, b integer); CREATE OR REPLACE FUNCTION test_fn(a integer, b integer) RETURNS text AS $$ result = object() import pickle return pickle.dumps({'a':a, 'b':b}) $$ LANGUAGE plpython3u
Now, let's query our new function:
Select All
1
SELECT test_fn(1,2)
You should receive a response similar to the following:
Select All
1
b'\x80\x03}q\x00(X\x01\x00\x00\x00aq\x01K\x01X\x01\x00\x00\x00bq\x02K\x02u.'
原地址 http://www.youlikeprogramming.com/2013/08/postgresql-9-1-installing-plpythonuplpython3u-python-in-windows/
相关文章推荐
- Thrift Python in windows
- 【Python错误】windows下使用pip/easy_install提示Fatal error in launcher: Unable to create process using...
- Sublime Text 2 for C/C++ and Python in Windows
- Mouse and keyboard operation in windows using python
- python error when compile file in windows
- Read Unicode characters from command-line arguments in Python 2.x on Windows
- Windows API Hooking in Python
- ODB hello world example using PostgreSQL in windows
- How can I force Python's file.write() to use the same newline format in Windows as in Linux (“\r\n”
- windows PostgreSQL 9.1 安装详细步骤
- 【Python错误】windows下使用pip/easy_install提示Fatal error in launcher: Unable to create process using...
- windows & linux (centOS/ubuntu) 下 PostgreSQL安装 python php 连接 PostgreSQL
- windows下 OpenCV in Python 配置
- python -mtimeit in windows
- windows 安装MySQL-python-1.2.4b4.win32-py2.7提示which was not found in the registry
- windows安装python mysqldb时报错python version 2.7 required,which was not found in the registry
- Python的开发插件PyDev在Eclipse下的安装过程(解决mylyn的问题in Windows)
- 转载:Setup OpenCV for Python in Windows
- windows下用Python连接mysql报错问题“MySQLdb in Python: “Can't connect to MySQL server on 'localhost'””
- windows下python如何安装模块或包? How to install package or module in windows OS when using PYTHON?