[英]I keep having Traceback (most recent call last): error each time I run my selenium file below. How can I fix this?
I'm running a selenium file with the following code in python and I keep having a traceback call error.我在 python 中运行带有以下代码的 selenium 文件,并且我一直遇到回溯调用错误。 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. urllib3 未导入或未安装。
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:除了
@Ankit_Gunner
在他们的回答中提到的两个原因之外:
Either urllib3 is not imported or not installed.
urllib3 未导入或未安装。
There can be another possibility as follows:可能还有另一种可能性,如下所示:
urllib3
or requests
module is backdated and needs a update. urllib3
或requests
模块已过时,需要更新。 In that case you need to upgrade urllib3
/ requests
module as:在这种情况下,您需要将
urllib3
/ requests
模块升级为:
Using pip
:使用
pip
:
pip install --upgrade requests
Using pip3
:使用
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. 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. 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.
再次运行代码后一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.