![](/img/trans.png)
[英]I get Traceback (most recent call last) each time I run this code, how to fix this?
[英]I keep having Traceback (most recent call last): error each time I run my selenium file below. How can I fix this?
我在 python 中運行帶有以下代碼的 selenium 文件,並且我一直遇到回溯調用錯誤。 我說不出問題是什么。 以下是我一直遇到的錯誤:
[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
我的代碼:
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")
urllib3 未導入或未安裝。
要導入,請使用
import urllib3
在文件的頂部。 要安裝寫入:
pip install urllib3
進入終端。
除了@Ankit_Gunner
在他們的回答中提到的兩個原因之外:
urllib3 未導入或未安裝。
可能還有另一種可能性,如下所示:
urllib3
或requests
模塊已過時,需要更新。 在這種情況下,您需要將urllib3
/ requests
模塊升級為:
使用pip
:
pip install --upgrade requests
使用pip3
:
pip3 install --upgrade requests
這最終對我有用
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 . 再次運行代碼后一切正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.