1

Unable to import lxml from terminal on MAC. Getting this below error

ERROR:

python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so, 2): Symbol not found: _PyUnicodeUCS4_AsASCIIString
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml/etree.so
  Expected in: dynamic lookup

>>> 

'import lxml' works fine

Python path

which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

when i look for lxml installation, everything looks fine

pip install lxml
Requirement already satisfied: lxml in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

pip2 install lxml
Requirement already satisfied: lxml in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

What am i missing here ? what could be wrong ? can you please help me.

SOLUTION: solved it by uninstalling lxml and re-installed by pip install lxml --no-binary :all:

Diesel Kumar
  • 215
  • 4
  • 11
  • 22
  • Possible duplicate of [undefined symbol: PyUnicodeUCS2\_Decode whilst trying to install psycopg2](https://stackoverflow.com/questions/2584198/undefined-symbol-pyunicodeucs2-decode-whilst-trying-to-install-psycopg2) – phd Nov 05 '17 at 13:54
  • Possible duplicate of [Cannot install Lxml on Mac os x 10.9](https://stackoverflow.com/questions/19548011/cannot-install-lxml-on-mac-os-x-10-9) – Nemo Jan 30 '18 at 16:16

1 Answers1

0

You have python compiled with UCS4 (4-bytes unicode) and lxml with UCS2. I.e., the extension and python are incompatible. Change one of them — that is, recompile python with --enable-unicode=ucs2 or recompile lxml with UCS4.

phd
  • 82,685
  • 13
  • 120
  • 165