import cx_Oracle Traceback (most recent call last):
File "", line 1, in
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:
这样做之后,有时仍然出现问题。参照这里的方法,需要设置环境变量: 方法1:
如果是 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