无法导入selenium,即使我在vscode中安装了python和pip

2024-09-28 17:00:11 发布

您现在位置:Python中文网/ 问答频道 /正文

尽管我已经安装了Python,并且可以在命令提示符下确认它enter image description here

VSCode还显示了安装的python

enter image description here

我也在同一个位置安装了pip enter image description here

当我运行DoImport selenium时,仍然会出现此错误 enter image description here

不知道我错过了什么


Tags: pipselenium错误vscode命令提示符doimport
2条回答

For using selenium in chrome you have to download selenium chrome driver not selenium. So, download the selenium chrome driver from below link & Include path in code. Note that, You have latest version of chrome

[链接]https://chromedriver.chromium.org/downloads

下载后,在代码中包含如下路径

driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")

请参考以下内容检查模块“selenium”的安装情况:

  1. 请使用命令“pip version”检查模块安装工具“pip”的源代码是否与显示在VS代码左下角的python相同:(如果不同,请使用快捷键Ctrl+Shift+`打开新的VS代码终端,它将自动进入所选环境。)

    enter image description here

  2. 在所选环境中完成安装后,我们可以使用“pip show selenium”检查其安装位置:..:\lib\site-packages

    enter image description here

运行:

enter image description here

参考:Python environment in VS Code

相关问题 更多 >