mattshma / bigdata

hadoop,hbase,storm,spark,etc..

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

python导致包时报错:undefined symbol: PyUnicodeUCS4_FromObject

mattshma opened this issue · comments

参照 这里 在centos6 安装的 python2.7 在导入包时报错:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import add_newdocs
  File "/usr/local/python/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/python/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/python/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/python/lib/python2.7/site-packages/numpy/core/__init__.py", line 26, in <module>
    raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: /usr/local/python/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_FromObject

重新编译 Python,添加 --enable-unicode=ucs4,即使用如下命令编译:

./configure --prefix=/usr/local/python-2.7.14 --enable-shared --enable-unicode=ucs4

如果导入时报错:ImportError: cannot import name _remove_dead_weakref,则说明存在多个 python 版本,需指定 LD_LIBRARY_PATH,如export LD_LIBRARY_PATH=${PYTHON_HOME}/lib:$LD_LIBRARY_PATH

查看 make 时的输出:

INFO: Can't locate Tcl/Tk libs and/or headers

Python build finished, but the necessary bits to build these modules were not found:
_bsddb             _tkinter           bsddb185
dbm                dl                 gdbm
imageop            readline           sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

执行:sudo yum install -y tk-devel

重新编译时报错:

/usr/local/python-2.7.14/lib/libpython2.7.a: could not read symbols: Bad value

由于之前已经编译过一次,这里先删除 /usr/local/python-2.7.14后,再重新 make 即可。

若 configure 编译参数也调整了,在python的编译目录先执行 sudo make clean

若编译安装问题太多的话,可以使用 Anaconda 节约生命。