我正在做一些初学者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
任何帮助都会非常有帮助。这是一个非常简单的脚本,我不知道为什么会发生这种情况!
提前致谢!
答案 0 :(得分:5)
错误说明了一切:
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
hash -r python
告诉bash将缓存位置重置为python可执行文件。hash -r pytho
n说的args太多,那么您可以使用rehash
命令。Python
2.7.10 更新为 2.7.11时,会出现问题/强> conda install python=2.7.10
来解决此问题。Python
降级为 2.7.10 ,也会有效。