Python: undefined symbol: PyUnicodeUCS4_Decode

1,137 views
Skip to first unread message

Louis Luangkesorn

unread,
Sep 19, 2014, 11:43:02 AM9/19/14
to gur...@googlegroups.com
This is actually a solved problem, but I'm posting this here because I have to do this again and I want to be able to find the answer, and it may be a sign that there is a problem in the setup.py script. (once I figure out where to send it, I'll submit it as a bug report)

When I was installing Gurobi python using Canopy I get

=======
import gurobipy
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-1a30be95fe9a> in <module>()
----> 1 import gurobipy

/Canopy/Canopy_64bit/User/lib/python2.7/site-packages/gurobipy/__init__.py in <module>()
----> 1 from .gurobipy import *

ImportError: /Canopy/Canopy_64bit/User/lib/python2.7/site-packages/gurobipy/gurobipy.so: undefined symbol: PyUnicodeUCS4_Decode
=======


What I think is the underlying issue is that Canopy Python is 16bit unicode support (I think)

>>> sys.maxunicode
65535

But Gurobi's setup.py script thinks that it is 32 bit

I solved this by copying the following into my 
userdir/Canopy/Canopy_64bit/User/lib/python2.7/site-packages/gurobipy folder

sudo cp /opt/gurobi563/linux64/lib/python2.7_utf16/gurobipy.so  .

thus replacing the gurobipy.so file that was there.  And now it works.

>>> execfile('/opt/gurobi563/linux64/examples/python/mip1.py')
Optimize a model with 2 rows, 3 columns and 5 nonzeros
Found heuristic solution: objective 2
Presolve removed 2 rows and 3 columns
Presolve time: 0.02s

Explored 0 nodes (0 simplex iterations) in 0.05 seconds
Thread count was 1 (of 4 available processors)

Optimal solution found (tolerance 1.00e-04)
Best objective 3.000000000000e+00, best bound 3.000000000000e+00, gap 0.0%
x 1
y 0
z 1
Obj: 3


===========

I get the opposite problem in Continuum Anaconda Python

>>> sys.maxunicode
1114111

>>> import gurobipy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "userdir/anaconda/lib/python2.7/site-packages/gurobipy/__init__.py", line 1, in <module>
    from .gurobipy import *
ImportError: userdir/anaconda/lib/python2.7/site-packages/gurobipy/gurobipy.so: undefined symbol: PyUnicodeUCS2_Decode

I solved this by copying the following into  /anaconda/lib/python2.7/site-packages/gurobipy/

sudo cp /opt/gurobi563/linux64/lib/python2.7_utf32/gurobipy.so .

with the same (successful) result

Louis

========
Ubuntu 14.04

Gurobi 5.6.3

Enthought Canopy Python 2.7.6 | 64-bit | (default, Jun  4 2014, 16:32:15) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2

Python 2.7.7 |Anaconda 2.0.1 (64-bit)| (default, Jun  2 2014, 12:34:02) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2

Jakob Sch.

unread,
Sep 21, 2014, 11:34:09 AM9/21/14
to gur...@googlegroups.com
Hi Louis,

The two python distributions that you mention are not officially supported by gurobi. It's nice that you found a workaround for your problem and shared it with the community.

Best regards,
Jakob

ALHUSSIN ABUDIYAH

unread,
Mar 4, 2015, 12:50:15 PM3/4/15
to gur...@googlegroups.com
Hi

Can you clarify more about this method to work gurobi with Anaconda because I have the same problem

Best,
Alhussin

Louis Luangkesorn

unread,
Oct 30, 2015, 12:49:34 PM10/30/15
to Gurobi Optimization
Oops, sorry I did not see this.  In case this is still a live issue (I have not updated my Gurobi yet), the problem was the shared library /site-packages/gurobipy/gurobipy.so, which triggered the error: undefined symbol: PyUnicodeUCS2_Decode

The issue is that Anaconda is 32 bit unicode encoding,which you can verify within Python with 
>>> sys.maxunicode
1114111

So somehow the install thinks that it is 16 bit unicode thus uses the shared library that is built requiring PyUnicodeUCS2_Decode.  So the solution is to go into the Python installation and copy the correct gurobipy.so shared library from /python2.7_utf32/gurobipy.so and replace the /site-packages/gurobipy/gurobipy.so with the version compiled with 32 bit unicode support.

Hope this helps.

Louis
Reply all
Reply to author
Forward
0 new messages