找不到导入错误符号:__PySlice_AdjustIndices

Import Error Symbol not found: __PySlice_AdjustIndices

我正在做一些初学者 Selenium 以在浏览器中自动执行任务。我已经使用 pip install selenium 安装了 Selenium,并且我知道它已成功安装,因为我看到了以下消息:Successfully installed selenium-3.9.0.

好的,很明显 Selenium 已启动并正在工作。

我想要运行这个python文件:

from selenium import webdriver
browser = webdriver.Firefox()
type(browser)
browser.get('http://inventwithpython.com')

但是,当我 运行 使用终端时,出现以下错误:

mustafas-mbp:PlayDivya mustafahoda$ python playDivya.py 
Traceback (most recent call last):
  File "playDivya.py", line 4, in <module>
    from selenium import webdriver
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 22, in <module>
    import httplib as http_client
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in <module>
    from array import array
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so

任何帮助都会非常有帮助。这是一个非常简单的脚本,我不知道为什么会这样!

提前致谢!

错误说明了一切:

Traceback (most recent call last):
  File "playDivya.py", line 4, in <module>
    from selenium import webdriver
.
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/array.so, 2): Symbol not found: __PySlice_AdjustIndices

原因及解决方法

  • 安装新版本的 python 时可能会出现此问题。在这些情况下,您可能需要 运行 hash -r python 告诉 bash 将 缓存 位置重置为 python 可执行文件。
  • 如果 hash -r python 说参数太多那么你可以使用 rehash 命令。
  • 根据讨论 Symbol not found: __PyCodecInfo_GetIncrementalDecoder,当 PythonPython 2.7.10[ 更新时会出现问题=35=] 到 2.7.11.
  • 如果您使用的是 conda 包,则需要 运行 conda install python=2.7.10 这将解决此问题。
  • 即使将 Python 降级到 2.7.10 也可以。
  • 最好的解决方案是