【问题标题】:how to change Python version used by plpython on Mac OSX?如何更改 plpython 在 Mac OSX 上使用的 Python 版本?
【发布时间】:2011-05-07 14:23:45
【问题描述】:

我已经使用来自EnterpriseDB 的安装程序在 Mac OSX 10.6 上安装了 PostgreSQL 9.0.4,并注意到在 plpython 中实现的存储过程使用 python 2.5。查看 plpython 库似乎证实了这一点(otool 在 mac 上的作用类似于 ldd 在 linux 上的作用):

host:~ user$ otool -L /Library/PostgreSQL/9.0/lib/postgresql/plpython2.so
/Library/PostgreSQL/9.0/lib/postgresql/plpython2.so:
/System/Library/Frameworks/Python.framework/Versions/2.5/Python (compatibility version 2.5.0, current version 2.5.1)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)

如何将其从 Python 2.5 更改为 Python 2.6 ?

亲切的问候,

ssc

【问题讨论】:

    标签: macos postgresql plpython


    【解决方案1】:

    您需要从源代码重建。在二进制分布中无法更改它。

    运行configure时,将环境变量PYTHON设置为您要使用的python二进制文件的完整路径,例如,

    ./configure --other-stuff ... PYTHON=/usr/bin/python2.6
    

    我猜你可以尝试让 EnterpriseDB 人员更新他们的构建例程。不确定他们选择 Python 版本的标准是什么。或者,也许从 MacPorts 安装。

    【讨论】:

      【解决方案2】:

      我应该将此作为对 Peter Eisentraut 答案的评论发布,但我一直按 Enter 键,然后在评论完成之前意外发布;另外,我想添加一些链接和其他内容:

      我最终完全按照 Peter 的建议进行了 - 从源代码和 EnterpriseDB forum 中的 posting this issue 重建。出于某种原因,我的论坛帖子出现在一个我以前从未听说过的用户名下,我什至可以阅读该用户的所有帖子。也许他/她在我之前登录,在我看来他们论坛软件中的一个相当大的错误:-(

      无论如何,构建 plpython 二进制文件无非就是 download 最新的 PostgreSQL 源代码,将其解压并以 documented 的形式将一些参数传递给 configure

      configure --with-python PYTHON=/usr/bin/python2.6
      

      然后,运行make 进行构建。尽管我系统上的默认 Python 版本是 2.6,并且我明确地将其作为参数传递,但 configure 会打印此消息

      checking for python... /usr/bin/python2.6
      checking for Python distutils module... yes
      checking Python configuration directory... /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config
      checking how to link an embedded Python application... -L/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config -lpython2.6 -ldl
      checking whether Python is compiled with thread support... yes
      

      但构建的二进制文件无论如何都使用 Python 2.7 安装,我什至不记得我安装过:

      otool -L <postgres build dir>/src/pl/plpython/plpython2.so 
      <postgres build dir>/src/pl/plpython/plpython2.so:
          /Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
          /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.10)
      

      这对我来说已经足够好了,我所需要的只是 2.5 的更新版本。还是很奇怪。

      现有的 plpython 二进制文件(使用 Python 2.5 的二进制文件)位于 EnterpriseDB 默认安装目录 /Library/PostgreSQL/9.0/lib/postgresql/plpython2.so 中,在同一文件夹中带有符号链接 plpython.so。我选择保留原件只是为了安全起见并重新符号链接而不是删除:

      sudo mv plpython2.so plpython25.so
      sudo cp <postgres build dir>/src/pl/plpython/plpython2.so plpython27.so
      sudo ln plpython27.so plpython2.so
      

      嗯,也许这应该进入维基......

      【讨论】:

      • 顺便说一句,我遇到了一个设置为 2.5 的 VERSIONER_PYTHON_VERSION 环境变量;很可能这就是 enterprisedb 安装程序正在查询以确定当前 python 版本的内容。 'man python' 也有一个内容丰富的 CHANGING THE DEFAULT PYTHON 部分。
      • 这适用于 RHEL5,只需相应地更改 postgres 目录。谢谢!
      最近更新 更多