2

I am doing some beginner Selenium to automate a task in the browser. I have installed Selenium using pip install selenium and I know it installed successfully because I saw the following message: Successfully installed selenium-3.9.0.

Okay so that's clear Selenium is up and working.

I want to run this python file:

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

However, when I run this using the terminal, I get the following error:

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

Any help would be super helpful. This is a very simple script and I have no idea why this is happening!

Thanks in advance!

Mustafa
  • 337
  • 7
  • 14

1 Answers1

5

The error says it all :

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

Reasons and Solution

  • This issue can arise when you install a new version of python. In those cases you may need to run hash -r python to tell bash to reset the cached location to the python executable.
  • If hash -r python says too many args then you can use rehash command.
  • As per the discussion Symbol not found: __PyCodecInfo_GetIncrementalDecoder the issue occurs when Python is updated from Python 2.7.10 to 2.7.11.
  • If you are using conda package you need to run conda install python=2.7.10 which will solve this problem.
  • Even downgrading Python to 2.7.10 will also work.
  • The best solution would be Re-Installing Selenium.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352