Python cx_Oracle installation note
SQLAlchemy is a powerful tool used in Python to operate databases. It supports MySQL, Oracle, PostgreSQL, SQLite, and Oracle. To use SQLAlchemy to manage Oracle Data, you must install cx_Oracle. Many problems encountered in this process are recorded as follows. Now you can install the correct cx_Oracle version in Windows Through pip install cx_Oracle. You need to distinguish between 10g and 11g, and install instantclient_11_2 (Please download it from the Oracle official website). ImportError: DLL load failed: the specified module cannot be found. Add the directory where instantclient_11_2 is located to the environment variable, but the environment variable sometimes does not take effect immediately. You can copy the oci. dll (the version must be correct) to the \ Python27 \ Lib \ site-packages directory, then the problem Unable to acquire Oracle environment handle occurs, copy oci. dll dependent dll, oraociei11.dll, and ocijdbc11.dll to the \ Python27 \ Lib \ site-packages directory. If it is not clear, copy the dll under the instantclient_11_2 directory to \ Python27 \ Lib \ site-packages directory can refer to: http://docs.oracle.com/cd/B12037_01/appdev.101/b10779/oci01int.htm#423364 # UNIXlibclnstsh. so.10.1libnnz10. solibociei. so # Windowsoci. dlloraociei10.dllorannzsbb10. dllLinux # first install rpmyum install rpm # oracle-instantclient-basic-10.2.0.3-1.x86_64.rpm please go to the Oracle official website to download rpm-ivh oracle-instantclient-basic-10.2.0.3-1.x86_64.rpmrpm-I * H cx_Oracle-5.1.2-10g-py27-1.x86_64.rpm # This file indicates that the installation was successful, depending on the location of python, may also be in other places ls/usr/lib/python2.7/site-packages/cx_Oracle.so problem 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 directoryThe problem is that the just installed libraries of the Oracle Instant Client aren't part 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 shocould be allowed 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 wit H the following content: vim/etc/ld. so. conf. d/oracle. add/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 in conf. 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 n Ew 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 shocould be able to use the cx_Oracle module in your Python shell: after doing so, sometimes problems still occur. For more information, see the following method. You must set the environment variable: Method 1: export PATH to add a variable to the/etc/profile file. This variable will be valid for all users in Linux, and "permanent ". Add LD_LIBRARY_PATH =$ {LD_LIBRARY_PATH}:/usr/lib/oracle/10.2.0.3/client64/libexport LD_LIBRARY_PATH to the end of the vi/etc/profile file. If the modification takes effect immediately, run the following code source/etc/profile. Then, check the system environment variables to see that the added item has taken effect. echo $ LD_LIBRARY_PATH Method 2: run the export command to define the variable, only valid for the current shell (BASH) (Temporary) export LD_LIBRARY_PATH =$ {LD_LIBRARY_PATH}:/usr/lib/oracle/10.2.0.3/client64/lib Question 2 import cx_OracleImportError: no module named cx_Oracle if python is installed 64-bit, copy the cx_Oracle file to the cd/usr/lib64/python2.7/site-packages/directory, usr/lib/python2.7/site-packages/cp cx_Oracle.so/usr/lib64/python2.7/site -packages/cx_Oracle.socp cx_Oracle-5.1.2-py2.7.egg-info/usr/lib64/python2.7/site-packages/cx_Oracle-5.1.2-py2.7.egg-info if the Ubuntu system requires attention For Debian and derivatives, this sys. path is augmented with directories for packages distributed within the distributio N. 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.7sudo mv site-packages/cx_Oracle * dist-packages/sudo rmdir site-packages/sudo ln-s dist-packages site-packagessudo ldconfig Thanks to http://bayo.opadeyi.net/2011/07/setting-up-cxoracle-on-ubuntu-1104.htmlSQLA You need to set the NLS_LANG environment variable for the Chinese character of lchemy Oracle. Otherwise, the Chinese character you read may be garbled, or the Unicode encoding error may occur when the insert data contains Chinese characters. You can set the environment variable # encoding in the Python code, otherwise: #1. chinese characters found by Oracle are garbled #2. when data is inserted, the # UnicodeEncodeError: 'ascii 'codec can't encode characters in position 1-7: ordinal not in range (128) OS. environ ['nls _ LANG '] = 'simplified chinese_china.utf8'