【问题标题】:Import Error Symbol not found: __PySlice_AdjustIndices未找到导入错误符号:__PySlice_AdjustIndices
【发布时间】:2018-07-31 12:23:27
【问题描述】:

我正在做一些初学者 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

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

提前致谢!

【问题讨论】:

    标签: python python-2.7 selenium selenium-webdriver importerror


    【解决方案1】:

    错误说明了一切:

    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 将 cached 位置重置为 python 可执行文件。
    • 如果hash -r python 说的参数太多,那么你可以使用rehash 命令。
    • 根据Symbol not found: __PyCodecInfo_GetIncrementalDecoder 的讨论,当 PythonPython 2.7.10 更新到 2.7.11 时会出现问题。
    • 如果您使用的是 conda 包,则需要运行 conda install python=2.7.10 来解决此问题。
    • 即使将 Python 降级到 2.7.10 也可以。
    • 最好的解决方案是Re-Installing Selenium

    【讨论】:

    • 是的,非常感谢!第一个建议有效hash -r python
    • 在导入 urllib2 时遇到了类似的问题,它再次依赖于数组包。上面的答案有帮助。
    猜你喜欢
    • 2018-12-19
    • 2021-12-21
    • 2021-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多