今天,在centos6.5下安装psycopg2,利用Python连接PostgreSQL数据库的时候,出现了一个undefined symbol: lo_truncate6的错误:

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: /mydev/pyweb/cancerdb/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: lo_truncate64

究其原因,正如 http://initd.org/psycopg/docs/faq.html 所描述:

“This means that Psycopg was compiled with lo_truncate() support (i.e. the libpq used at compile time was version >= 8.3) but at runtime an older libpq dynamic library is found. Fast-forward several years, if the message reports undefined symbol: lo_truncate64 it means that Psycopg was built with large objects 64 bits API support (i.e. the libpq used at compile time was at least 9.3) but at runtime an older libpq dynamic library is found.”

(psycopg在利用lo_truncate()编译的时候需要libpq至少要9.3以上版本,但是在编译的时候却发现了一个版本较低的libpq。)

在网上看到有不少人通过修改psycopg2安装包下的 setup.cfg ,添加PostgreSQL的 pg_config,再重新手动安装psycopg2来解决:

shenweiyan@localhost :: ~
=> vi setup.cfg
.......
# full path.
pg_config=/usr/local/psql-/bin/pg_config

# Set to  to use Python datetime objects for default date/time representation.
use_pydatetime=
.......

尝试才发现该方法不能够从根本上解决该问题,undefined symbol: lo_truncate6的报错依然存在。

经过一番摸索,结合 psycopg2 官方文档,后来才发现需要把PostgreSQL的 libpq.so.5 跟系统的 libpq.so.5 进行替换,再重新安装psycopg2,问题即可解决:

1、find what is the libpq dynamic library used at runtime(查找运行过程中所用的libpq动态库):

$ ldd /path/to/packages/psycopg2/_psycopg.so | grep libpq   

2、You can avoid the problem by using the same version of the pg_config at install time and the libpq at runtime(替换运行过程中的libpq动态库):

root@localhost :: /usr/local/download/psycopg2-
=> cd /usr/lib64
root@localhost :: /usr/lib64
=>
root@localhost :: /usr/lib64
=> /lib/libpq.so. ./

3、重新安装psycopg2,解决问题。

shenweiyan@localhost :: /mydev/pyweb/download/psycopg2-
=> python
Python  (default, Jan  , ::)
[GCC   (Red Hat -)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>

ok,问题解决!!!


psycopg2关于undefined symbol: lo_truncate64解决方法的更多相关文章

  1. Linux下Python3.5使用pyqt5.11报错 ImportError: /usr/local/lib/python3.5/dist-packages/PyQt5/QtCore.so: undefined symbol: PySlice_AdjustIndices 解决方法

    我用的Linux自带的是Python3.5版本,运行pip3 install PyQt5, 下载的是PyQt5.11,运行PyQt5程序会报错: ImportError: /usr/local/lib ...

  2. [转载][jQuery] Cannot read property ‘msie’ of undefined错误的解决方法

    参考 [jQuery] Cannot read property ‘msie’ of undefined错误的解决方法 ---------------------------------------- ...

  3. [jQuery1.9]Cannot read property ‘msie’ of undefined错误的解决方法

    原文:[jQuery1.9]Cannot read property 'msie' of undefined错误的解决方法 $.browser在jQuery1.9里被删除了,所以项目的js代码里用到$ ...

  4. LaTex: Undefined citation warnings 解决方法

    参考 Undefined citations LaTex: Undefined citation warnings 解决方法 在使用TexMaker编译文献的时候,出现引用参考文献的问题: Packa ...

  5. php中提示Undefined index的解决方法

    我们经常接收表单POST过来的数据时报Undefined index错误,如下: $act=$_POST['action']; 用以上代码总是提示 Notice: Undefined index: a ...

  6. Z-BlogPHP 安装出现 (8) Undefined offset: 6 解决方法

    有些cp面板的空间会在每个网页头部和页脚增加两个调用的文件,导致zblogPHP安装出错:(8) Undefined offset: 6 主要国外的主机中PHP配置文件两个选项auto_prepend ...

  7. PHP LINUX Notice: undefined $_GET完美解决方法

    PHP Notice: undefined 平时用$_GET[‘xx’] 取得参数值时,如果之前不加判断在未传进参数时会出现这样的警告: PHP Notice: undefined index xxx ...

  8. xcode duplicate symbol _GAD_MD5 解决方法

    添加了mobi的广告平台后,在Device状态打包时,出现此错误. duplicate symbol _GAD_MD5 in: 解决方法: Targets ->Build Setting  中设 ...

  9. Call to undefined function curl_init()解决方法

    今天在使用php中的 curl 扩展时 在开启

随机推荐

  1. UML中九种图的理解

    1.用例图. 用例图是用来描述用户需求的,从用户的角度来描述系统的功能,并指出各个执行者.强调谁在使用,系统的执行者是谁. 2.类图. 用来定义系统中的类,包括描述类的结构和类之间的关系.类图的主要作 ...

  2. 用Python写的简单脚本更新本地hosts

    这两天Google墙得严重,于是就产生了做个一键更新hosts的脚本的想法. 由于正在学习Python,理所当然用Python来写这个脚本了. 接触比较多的就是urllib2这个库,习惯性的impor ...

  3. 关于STM32工程的错误,狗血错误。。。..\CMSIS\core_cm3.h(1087): error: #20: identifier "IRQn_Type" is undefined

    这件事还是要写一篇博客了,为了后来的人不换致命性的错误 辛辛苦苦写的一个四个不同的引脚不同时钟不同寄存器分别产生四种不同占空比不同周期的信号方波程序超级经典  PS:页尾上传PWM波形产生工程附件供大 ...

  4. CSS之Hack

    一.类内部Hack IE都能识别*;标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important, IE7能识别*,也能识别!important; FF不能识别*,但能识别!imp ...

  5. 有序线性搜索(Sorted/Ordered Linear Search)

    如果数组元素已经排过序(升序),那我们搜索某个元素就不必遍历整个数组了.在下面给出的算法代码中,到任何一点,假设当前的arr[i]值大于搜索的值data,就可以停止搜索了. #include<s ...

  6. ZOJ(3455)

    Shizuka's Letter Time Limit: 2 Seconds      Memory Limit: 65536 KB Nobita receives a letter from Shi ...

  7. 【Python】Coding the Matrix:Week 5: Dimension Homework 5

    这一周的作业,刚压线写完.Problem3 没有写,不想证明了.从Problem 9 开始一直到最后难度都挺大的,我是在论坛上看过了别人的讨论才写出来的,挣扎了很久. Problem 9在给定的基上分 ...

  8. Python 字符串相关操作

    # 1 * 重复输出字符串 print('hello'*2) # 2 [] ,[:] 通过索引获取字符串中字符,这里和列表的切片操作是相同的,具体内容见列表 print('helloworld'[2: ...

  9. DOTween 模仿NGUI Tween

    最近再做一个小的项目,只要使用的是DOTween 动画. 但是感到DOTween 在某些方面不如 NGUI的Twenn 比较好用 所以就模仿了一下 在此,请各位大神指点一下 public class ...

  10. Maven引入hadoop依赖包出错解决办法

    错误: ArtifactTransferException: Failure to transfer org.apache.hadoop:hadoop-hdfs:jar:2.6.0 from http ...