随笔 - 23  文章 - 2 评论 - 2 阅读 - 51545
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

系统环境:RHEL5.4   python2.5(手动编译安装,系统带有2.4版本)

在使用python脚本访问数据库时,需要导入cx_Oracle模块    

$>>>import cx_Oracle
Traceback (most recent call last):
  File "/ghca/monitor/async_Msg_MQDis/run.py", line 2, in <module>
    import async_Msg_MQDis
  File "/ghca/monitor/async_Msg_MQDis/async_Msg_MQDis.py", line 1, in <module>
    import cx_Oracle
ImportError: No module named cx_Oracle
分析原因:
1、怀疑缺少模块包
[oracle@radius1 async_Msg_MQDis]$ rpm -qa|grep cx
cx_Oracle-5.1.2-1
发现已安装,查询包安装目录
[oracle@radius1 async_Msg_MQDis]$ rpm -ql cx_Oracle-5.1.2-1|less
/usr/lib64/python2.4/site-packages/cx_Oracle.so
/usr/share/doc/cx_Oracle-5.1.2
2、切换到模块目录下进行导入
$cd /usr/lib64/python2.4/site-packages
[oracle@radius1 site-packages]$ python
Python 2.5.2 (r252:60911, Apr 11 2013, 14:10:12) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./cx_Oracle.so: undefined symbol: PyUnicodeUCS4_Decode
>>> 
3、猜测可能是python版本与cx_Oracle对应版本不一致导入
[oracle@radius1 ~]$ ls /usr/bin/python2.4 
/usr/bin/python2.4
[oracle@radius1 ~]$ /usr/bin/python2.4
Python 2.4.3 (#1, Jun 11 2009, 14:09:37) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> 
导入成功
总结:中途也曾重新下载cx_Oracle-5.1.2-10g-py25-1.i386.rpm和cx_Oracle-5.1.2-10g-py25-1.x86_64.rpm进行尝试,均未导入成功,并且在安装了cx_Oracle*py25*.x86_64.rpm版本进行导入时报缺少“libpython2.5.so.1.0”库文件错误。在公司测试机上装有python2.6,其中 /usr/lib/libpython2.6.so.1.0 库文件属于python-libs-2.6.6-20.el6.i686包。
posted on   lzc_jack  阅读(1668)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示