5

我在 oracle Linux EL7 上有 python 3.6.8 我使用安装了 pip3

yum install python36-pip

但是,当我调用 pip3 时,它会出现库错误

pip3

Traceback (most recent call last):
  File "/bin/pip3", line 8, in <module>
    from pip import main
  File "/usr/lib/python3.6/site-packages/pip/__init__.py", line 42, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/usr/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 35, in <module>
    import plistlib
  File "/usr/lib64/python3.6/plistlib.py", line 65, in <module>
    from xml.parsers.expat import ParserCreate
  File "/usr/lib64/python3.6/xml/parsers/expat.py", line 4, in <module>
    from pyexpat import *
ImportError: /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so: undefined symbol: XML_SetHashSalt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/bin/pip3", line 12, in <module>
    from pip._internal import main
  File "/usr/lib/python3.6/site-packages/pip/__init__.py", line 42, in <module>
    from pip.utils import get_installed_distributions, get_prog
  File "/usr/lib/python3.6/site-packages/pip/utils/__init__.py", line 27, in <module>
    from pip._vendor import pkg_resources
  File "/usr/lib/python3.6/site-packages/pip/_vendor/pkg_resources/__init__.py", line 35, in <module>
    import plistlib
  File "/usr/lib64/python3.6/plistlib.py", line 65, in <module>
    from xml.parsers.expat import ParserCreate
  File "/usr/lib64/python3.6/xml/parsers/expat.py", line 4, in <module>
    from pyexpat import *
ImportError: /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so: undefined 
symbol: XML_SetHashSalt

我试图看看是否有任何替代 pyexpat.*.so 但似乎没有 ldd 在下面的最后一行是输出

[root@whf00jkd python3.6]# ldd  /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so
        linux-vdso.so.1 =>  (0x00007ffd76bf9000)
        libexpat.so.1 => /scratch/oraofss/app/oraofss/product/18.0.0/client_1/lib/libexpat.so.1 (0x00007fec3a94a000)
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007fec3a422000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fec3a206000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fec39e38000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fec39c34000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fec39a31000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fec3972f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fec3ad81000)

我搜索了 libexpat.so.1

[root@whf00jkd python3.6]# whereis libexpat.so.1
libexpat.so: /usr/lib/libexpat.so.1 /usr/lib/libexpat.so /usr/lib64/libexpat.so.1 /usr/lib64/libexpat.so
[root@whf00jkd python3.6]# ls -ltr /usr/lib/libexpat.so.1
lrwxrwxrwx. 1 root root 17 Apr  1  2019 /usr/lib/libexpat.so.1 -> libexpat.so.1.6.0
[root@whf00jkd python3.6]# ls -ltr /usr/lib64/libexpat.so.1
lrwxrwxrwx. 1 root root 17 Apr  1  2019 /usr/lib64/libexpat.so.1 -> libexpat.so.1.6.0

并在 /usr/lib64/python3.6/lib-dynload/ 中添加了一个链接 libexpat.so.1 -> /usr/lib/libexpat.so.1 但这并没有消除错误

请帮忙

4

4 回答 4

7

指向错误位置的 libexpat.so.1 使用 export LD_LIBRARY_PATH=/lib64/:$PATH 修复了它

ldd /usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so
        linux-vdso.so.1 =>  (0x00007fff073f1000)
        libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f9ba53ce000)
        libpython3.6m.so.1.0 => /lib64/libpython3.6m.so.1.0 (0x00007f9ba4ea9000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9ba4c8d000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f9ba48bf000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f9ba46bb000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f9ba44b8000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f9ba41b6000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f9ba5807000)
于 2020-08-17T06:52:30.380 回答
3

我有完全相同的错误。

系统信息

  • 带有 CentOS 7.9 的虚拟机
  • 蟒蛇 3.6

解决方案

我们安装了另一个软件,它带有它自己的 libexpat 版本。我们还修改了环境变量 LD_LIBRARY_PATH 以包含该软件的 lib 目录。这导致 pip加载错误的库。

在取消设置 LD_LIBRARY_PATH/从 LD_LIBRARY_PATH 中删除软件后,一切都很好。

于 2021-06-15T12:02:00.383 回答
1

这就是为我解决问题的原因。我使用的是 Python 3.6,并尝试使用 PIP 安装模块。我收到以下错误。

ImportError:/opt/rh/rh-python36/root/usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so:未定义符号:XML_SetHashSalt

给出 ldd 后跟查找映射的路径。

ldd /opt/rh/rh-python36/root/usr/lib64/python3.6/lib-dynload/pyexpat.cpython-36m-x86_64-linux-gnu.so

检查 - libexpat.so.1 的映射。在我的情况下,它指的是不正确的 oracle 路径 - /u01/oracle/product/12.1.0.2/lib/libexpat.so.1

所以我在上面的目录中重命名了libexpat.so.1。

重命名后,再给ldd,应该是指向/lib64/libexpat.so.1

更正映射后,我就可以进行 pip install 了。

谢谢大家的帮助。

对我有帮助的链接:

https://ubuntuforums.org/showthread.php?t=2094005

https://askubuntu.com/questions/546654/python-error-when-opening-software-center

于 2021-03-23T15:17:36.107 回答
0

你是如何安装 Python 3 的?在我的 Oracle Linux 7 安装中,我从 yum.oracle.com 上的 ol7_latest 安装了 python3:

$ yum info python3
Installed Packages
Name        : python3
Arch        : x86_64
Version     : 3.6.8
Release     : 13.0.1.el7
Size        : 39 k
Repo        : installed
From repo   : ol7_latest

如果没有安装 python36-pip,pip3 会按预期工作,例如:

$ pip3 install --user cx_Oracle
Collecting cx_Oracle
  Using cached https://files.pythonhosted.org/packages/16/1d/36ecde56e0522f1a1cea7b4d4333f88b1062e0c5287fc67f522ceacc053c/cx_Oracle-8.0.0-cp36-cp36m-manylinux1_x86_64.whl
Installing collected packages: cx-Oracle
Successfully installed cx-Oracle-8.0.0
于 2020-08-31T15:09:11.620 回答