Fixing "Symbol not found: _PyUnicodeUCS2_Compare and _PyUnicodeUCS2_AsASCIIString"

I've got a new client with a legacy Django project running on Python 2.7 with Pandas.

When I was configuring my local OS X environment I got a bunch of nasty errors:

ImportError: dlopen(/Users/mike/.pyenv/versions/project/lib/python2.7/site-packages/pandas/hashtable.so, 2): Symbol not found: _PyUnicodeUCS2_Compare  
  Referenced from: /Users/mike/.pyenv/versions/project/lib/python2.7/site-packages/pandas/hashtable.so
  Expected in: flat namespace
 in /Users/mike/.pyenv/versions/project/lib/python2.7/site-packages/pandas/hashtable.so

My first assumption was to upgrade Pandas from 0.15.1 to the most recent 0.18.1, but that didn't help. I rolled back to Pandas 0.15.1 to avoid any possible regressions.

After tens minutes of reading traceback messages and googling, I managed to fix that error with running $ pip install -U cython.

After that I've got:

  ImportError: dlopen(/Users/mike/.pyenv/versions/2.7.12/envs/project/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyUnicodeUCS2_AsASCIIString
    Referenced from: /Users/mike/.pyenv/versions/2.7.12/envs/project/lib/python2.7/site-packages/numpy/core/multiarray.so
    Expected in: flat namespace
   in /Users/mike/.pyenv/versions/2.7.12/envs/project/lib/python2.7/site-packages/numpy/core/multiarray.so

It seemed to be fixed in the most recent Numpy version, so I ran $ pip install -U numpy pandas, and the error disappeared.

I hope this short blog post will save your time. You're welcome to share your experience with fixing similar not obvious issues.

Michael Samoylov

Python, JavaScript and Swift Expert with 12+ years of experience.

Vilnius, Lithuania https://monmar.tech

Subscribe to Michael Samoylov

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!