在线安装

$ wget https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip -V  #查看pip版本

或者将网页中的代码复制到get-pip.py中再执行

 
离线安装
cx_Oracle 可以到这里下载:http://cx-oracle.sourceforge.net/
旧版本的下载地址:http://sourceforge.net/projects/cx-oracle/files/

# 先安装 rpm
$ yum install rpm

# oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm 请到 Oracle 官网下载
rpm -ivh oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm
rpm -ivh cx_Oracle-5.1.2-10g-py27-1.x86_64.rpm
# 有这个文件表示安装成功,根据 python 的位置,也可能在其他地方
ls /usr/lib/python2.7/site-packages/cx_Oracle.so

问题 1

import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory

The problem is that the just installed libraries of the Oracle Instant Client aren’t part of the default library path of your CentOS installation. Either you have to extend the LD_LIBRARY_PATH Bash variable of your current user or you have to add the lib directory of the Instant Client installation to the system-wide library path if all users should be allowed to use the Oracle Instant Client. To do so you have to create a new file, e.g. oracle.conf, in the /etc/ld.so.conf.d directory with the following content:

vim /etc/ld.so.conf.d/oracle.conf

添加

/usr/lib/oracle/10.2.0.3/client64/lib/

This tells ldconfig to also look for libraries in the lib folder of the Instant Client installation. To update the library cache just call ldconfig without any parameter. This will take a while since ldconfig will re-read every configured library folder and add its content to the library cache. The new oracle.conf file has to be owned by the root user as well as ldconfig has to be called as the root user. Afterwards so should be able to use the cx_Oracle module in your Python shell:

这样做之后,有时仍然出现问题。参照这里的方法,需要de >设置环境变量de>:

方法1:
export PATH
在/etc/profile文件中添加变量,该变量将会对Linux下所有用户有效,并且是“永久的”。

vi /etc/profile

在文件末尾添加

LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/oracle/10.2.0.3/client64/lib
export LD_LIBRARY_PATH

要是刚才的修改马上生效,需要执行以下代码

source /etc/profile

这时再查看系统环境变量,就能看见刚才加的东西已经生效了

echo $LD_LIBRARY_PATH

方法2: 直接运行export命令定义变量,只对当前shell(BASH)有效(临时的)

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/oracle/10.2.0.3/client64/lib

问题 2

import cx_Oracle
ImportError: No module named cx_Oracle

如果安装的 python 64 位,需要把cx_Oracle文件复制到 /usr/lib64/python2.7/site-packages/ 目录下

cd /usr/lib/python2.7/site-packages/
cp cx_Oracle.so /usr/lib64/python2.7/site-packages/cx_Oracle.so
cp cx_Oracle-5.1.2-py2.7.egg-info /usr/lib64/python2.7/site-packages/cx_Oracle-5.1.2-py2.7.egg-info

如果是 Ubuntu 系统则需要注意

For Debian and derivatives, this sys.path is augmented with directories for packages distributed within the distribution. Local addons go into /usr/local/lib/python/dist-packages, Debian addons install into /usr/{lib,share}/python/dist-packages. /usr/lib/python/site-packages is not used.

cd /usr/lib/python2.7
sudo mv site-packages/cx_Oracle* dist-packages/
sudo rmdir site-packages/
sudo ln -s dist-packages site-packages
sudo ldconfig

Thanks to http://bayo.opadeyi.net/2011/07/setting-up-cxoracle-on-ubuntu-1104.html

SQLAlchemy Oracle 的中文问题

你需要设置 de >NLS_LANGde> 环境变量,否则你读取出来的中文可能是乱码,或者当 insert 的数据有中文时会导致 Unicode 编码错误。

你可以在 Python 代码中这么设置环境变量

# 设置编码,否则:
# 1. Oracle 查询出来的中文是乱码
# 2. 插入数据时有中文,会导致
# UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-7: ordinal not in range(128)
os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'

参考自:https://www.cnblogs.com/restran/p/4787609.html

CentOS安装Python模块cx_Oracle的更多相关文章

  1. windows下安装python模块

    如何在windows下安装python模块 1. 官网下载安装包,比如(pip : https://pypi.python.org/pypi/pip#downloads) pip-9.0.1.tar. ...

  2. pycharm安装python模块

    这个工具真的好好,真的很喜欢,它很方便,很漂亮,各种好 pycharm安装python模块:file-setting-搜索project inte OK

  3. 转: CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法

    from: http://www.linuxde.net/2014/05/15576.html CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法 2014/05/ ...

  4. aix5下安装python和cx_Oracle

    之前写了一个 linux下安装python和cx_Oracle 这次其实差不多. 1.解压安装包: Python-2.5.4.tar.bz2 cx_Oracle-5.0.4.tar.gz 2.安装py ...

  5. windows下pip安装python模块时报错

    windows下pip安装python模块时报错总结  装载于:https://www.cnblogs.com/maxaimee/p/6515165.html 前言: 这几天把python版本升级后, ...

  6. CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法

    CentOS 6.4安装pip,CentOS安装python包管理安装工具pip的方法如下: 截至包子写本文的时候,pip最新为 1.5.5 wget --no-check-certificate h ...

  7. pip安装python模块遇到一直出现retrying的问题

    最近安装python模块,遇到这样的一个问题如图所示: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status= ...

  8. windows下pip安装python模块时报错【转】

    windows下pip安装python模块时报错总结 请给作者点赞--> 原文链接 1 权限问题 C:\Users\ljf>pip install xlwt Exception: Trac ...

  9. windows安装Python模块:requests

    个人在windows10安装python模块requests如下过程: 1.下载requests模块:首先打开powershell, cd到你要下载文件的位置(我的是d:\softwareinstal ...

随机推荐

  1. 基于C++的牛顿切线法演示

    牛顿切线法 中心思想: 利用目标函数二阶泰勒多项式的最优解作为函数的近似最优解.如果新的近似最优解满足计算精度,则终止计算,否则将函数在新点展开成二阶泰勒多项式,用新的泰勒多项式的最优解作为函数的近似 ...

  2. pycharm操作

  3. flutter Row 垂直或水平放置多个widget

    使用行(Row)水平排列widget,使用列(Column)垂直排列widget.在行或列中嵌套行或列实现复杂的布局.如下图所示: 此布局按行排列.该行包含两个子布局,左侧一列和右侧的图片 对于行(R ...

  4. Flask之 安装与HelloWorld

    安装Flask 首先我们来安装Flask.最简单的办法就是使用pip. pip install flask 然后打开一个Python文件(app.py),输入下面的内容并运行该文件.然后访问local ...

  5. Metaclasses

    1.Metaclasses Metaclasses是创建class(对象)的东西,它们是描述类的类,我们经常使用所理解的对象和class以及Metaclasses可以理解成以下形式: MyClass ...

  6. Python学习:函数式编程(lambda, map() ,reduce() ,filter())

    1. lambda: Python 支持用lambda对简单的功能定义“行内函数” 2.map() : 3.reduce() : 4.filter() : map() ,reduce() , filt ...

  7. Ubuntu 18.04 使用Systemd管理MySQL 5.6

    转自:https://blog.csdn.net/skykingf/article/details/45225981 如何用Systemd管理 general 包安装的MySQL呢? 首先看看yum安 ...

  8. 工控随笔_12_西门子_WinCC的VBS脚本_03_变量类型

    说到编程语言,总是绕不开数据类型,因为数据类型决定了数据可以进行什么样的操作.同时数据类型 从广义上来说是一种数据结构,在过程式编程的过程中,曾经有过这样一种说法: 程序 = 数据结构 + 算法 可见 ...

  9. 360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法

    360或者金山毒霸可能会导致HP网络打印机驱动安装失败“数据无效”的解决办法     同事办公室的打印机是网线接口的那种网络打印机,不是直接连到电脑的那种,他电脑安装了360和金山毒霸,WIN10下安 ...

  10. 《剑指offer(第二版)》面试题64——求1+2+...+n

    一.题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字以及条件判断语句 (即三元运算符,A? B : C) 二.题解 虽然求和问 ...