I'm running a selenium file with the following code in python and I keep having a traceback call error. I can't tell what the problem is. Below is the error I keep having:
[Traceback (most recent call last): File "C:\Users\Whizzy.Ellah\PycharmProjects\virtual_assistant_final_year_project\selenium_web.py", line 2, in from selenium import webdriver File "C:\anacondaF\envs\finalYrProject\lib\site-packages\selenium\webdriver_init_.py", line 18, in from .firefox.webdriver import WebDriver as Firefox # noqa File "C:\anacondaF\envs\finalYrProject\lib\site-][1]Traceback (most recent call last):
File "C:\Users\Whizzy.Ellah\PycharmProjects\virtual_assistant_final_year_project\selenium_web.py", line 2, in <module>
from selenium import webdriver
File "C:\anacondaF\envs\finalYrProject\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "C:\anacondaF\envs\finalYrProject\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 26, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "C:\anacondaF\envs\finalYrProject\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 40, in <module>
from .remote_connection import RemoteConnection
File "C:\anacondaF\envs\finalYrProject\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 26, in <module>
import urllib3
ModuleNotFoundError: No module named 'urllib3'
Process finished with exit code 1
My code:
import time
from selenium import webdriver
from selenium.webdriver import chrome
class web_driver_info():
def __int__(self):
self.driver = webdriver.Chrome(executable_path=r'C:\\Users\\Whizzy.Ellah\\PycharmProjects\\virtual_assistant_final_year_project\\chromedriver.exe')
def get_info(self, query):
self.query = query
self.driver.get(url='https://www.wikipedia.org')
class_instance = web_driver_info()
class_instance.get_info("Hello")
Either urllib3 is not imported or not installed.
To import, use
import urllib3
at the top of the file. To install write:
pip install urllib3
into terminal.
Apart from the two reasons mentioned by @Ankit_Gunner
in their answer that:
Either urllib3 is not imported or not installed.
There can be another possibility as follows:
urllib3
or requests
module is backdated and needs a update. In that case you need to upgrade urllib3
/ requests
module as:
Using pip
:
pip install --upgrade requests
Using pip3
:
pip3 install --upgrade requests
This is what finally worked for me
I tried changing the virtual environment from anaconda to python virtual environment by deactivating the anaconda virtual env that is being used by typing conda deactivate finalYrProject
(finalYrProject is the name of my virtual environment) through the anaconda command prompt.
Also, I had to change the base interpreter - ie Python interpreter by clicking on the file tab in Pycharm > settings > Python interpreter > settings' icon near the already used python interpreter selected > Show All and selected from the list of Python interpreters I had. And after running the code again everything works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.