1

Screen Shot

Link to workbook showing issue:`

https://colab.research.google.com/drive/1Zf8YTHRLOL6-ez1SWvzZEVZpkelrG2Kz?usp=sharing

!apt-get update
!apt install chromium-chromedriver
!pip install selenium
from selenium import webdriver

Google Colab + Account on Chrome Browserenter image description here

I have run various scripts for the last two years and no issues.

Today I get the following error:

ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)


  • I have posted the same question today: https://stackoverflow.com/questions/72128604/running-selenium-in-google-colab-without-getting-this-error I found a workaround, but I don't think it is the best option. I am waiting to see if someone has a better solution. I will post my workaround anyway. – user3347814 May 05 '22 at 15:35

1 Answers1

1

The error relates to the typing library. I do not know exactly why this is happening and I hope someone has a better solution than mine, but editing the file that calls this library worked for me:

# Install Normal Selenium Stuff

!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')

## This edits the part of the file that gives the error:

with open('/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/virtual_authenticator.py', 'r') as file:
  
    # read a list of lines into data
    data = file.readlines()

data[21] = 'from typing_extensions import Literal\n'

with open('/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/virtual_authenticator.py', 'w') as file:

    file.writelines( data )

# Calls Selenium (It is important to edit the file before calling seleninum):

from selenium import webdriver

I know this is probably not the best solution, but it worked for me. I hope someone can come up with a better solution and explain why this is happening. Meanwhile, this will probably work for most people.

user3347814
  • 895
  • 9
  • 22
  • 42
  • The error relates to "import Literal" on virtual_authenticator.py. I have no idea what it does, but I also found out that you can delete the line that does this import and Selenium works anyway. I have substitute this line with "from typing_extensions import Literal" just to keep loading this library, but apparently this is not very important. – user3347814 May 05 '22 at 15:45