Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cx_Oracle.so: undefined symbol:PyUnicodeUCS2_AsEncodedString

I am having issiues installing cx_oracle. I have installed oracle instantclient and cx_oracle oracle packages ones installed i am getting this error while importing cx_oracle. i am running ubuntu 11.10 as host.

import cx_Oracle
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: /usr/lib/python2.7/dist-packages/cx_Oracle.so: undefined symbol:PyUnicodeUCS2_AsEncodedString

any one have any idea how to resolve this issue

cheers

like image 835
nashr rafeeg Avatar asked Oct 31 '11 09:10

nashr rafeeg


People also ask

What is import cx_Oracle in Python?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions. cx_Oracle 8.3 was tested with Python versions 3.6 through 3.10.

Does cx_Oracle require Oracle client?

Using cx_Oracle requires Oracle Client libraries to be installed. These provide the necessary network connectivity allowing cx_Oracle to access an Oracle Database instance. Oracle Client versions 19, 18, 12 and 11.2 are supported.

Is Oracle compatible with Python?

Your applications can also use Oracle's document storage SODA calls. The cx_Oracle API conforms to the Python Database API v2. 0 Specification with a considerable number of additions and a couple of exclusions.


2 Answers

Most probably your Python install uses another unicode format (ucs4) and cx_oracle was compiled with ucs2.

You can install cx_Oracle 5.0.4 with the unicode flag. That worked for me but there is some bug: strange Oracle error: "invalid format text"

Or compile the latest cx_oracle yourself. http://mrpolo.com.ve/?p=178 (its some language i don't know but it helped)

like image 116
froZiegler Avatar answered Sep 20 '22 11:09

froZiegler


I addition to @froZieglers answer. When I came along the cx_Oracle page there was no "...Unicode..."-Variant to download anymore. Luckily compiling it myself from source was not a big a hassle then I expected.

Here a summary about what I did (Ubuntu 12.04 LTS, 64bit):

  • install the proper Oracle XE client rpm with alien (11g, 64bit, etc...)
    • it installs th /u01/..., I had to adjust .profile too, of course.
  • download cx_Oracle source-tar, untar, cd into
    • I did the ln -s command on the so-lib on Oracle, as said in BUILD text file
  • Install Python headers with sudo aptitude install python-dev
  • Compile with python setup.py build
  • Install with sudo python setup.by install
    • First try failed with distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
    • patched setup.py with setting userOracleHome = "/u01/app/oracle/product/11.2.0/xe" after os.getenv("ORACLE_HOME")
    • sudo python setup.by install then worked
  • Check with python -c 'import cx_Oracle' succeeded.
like image 39
towi Avatar answered Sep 19 '22 11:09

towi