Python: 导入错误:没有名为Selenium的模块 Windows

2 投票
2 回答
5681 浏览
提问于 2025-06-08 05:49

我在Windows 10上使用Python 3.6。我用以下命令创建了一个虚拟环境:

python -m venv venv

然后我安装了一些包,还用这个命令安装了selenium:

pip install selenium

但是当我在命令行中导入selenium时,出现了一个错误,提示:

ImportError: No module named selenium

而当我在VSCode中运行同样的代码时,没有任何错误。我搞不懂这是为什么。另外,我尝试过卸载并重新安装整个环境,但没有看到任何变化。

注意:我打算把这个项目部署到Heroku上。所以请给我一些你认为在部署到Heroku时需要注意的建议。

相关问题:

  • 暂无相关问题
暂无标签

2 个回答

1

要安装selenium

C:\Automation\DevelopBranch> pip install selenium

请检查一下Selenium是否已经安装。

C:\Automation\DevelopBranch>pip freeze
selenium==3.141.0
urllib3==1.25.6
You are using pip version 9.0.1, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' comm
and.

代码:

from selenium import webdriver:
driver = webdriver.Chrome(executable_path=r"path of chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 20)
driver.get("https://www.google.com")
1

我很抱歉这样说……但是通过运行以下代码,它就成功了:

python main.py

撰写回答