【问题标题】:Selenium webdriver imports correct in the Python shell, but not when I write a script [duplicate]Selenium webdriver在Python shell中正确导入,但在我编写脚本时不正确[重复]
【发布时间】:2020-03-22 06:02:49
【问题描述】:

所以我尝试在 python 脚本中使用 selenium webdriver,如下所示:

from selenium import webdriver

现在,当我在 python shell 中执行此操作时,这一切都很好,但如果我将其写入脚本,它会告诉我

Traceback (most recent call last):
  File "c:/Users/gvasquez/Scripts/viaUpdate.py", line 2, in <module>
    from Selenium import webdriver
ModuleNotFoundError: No module named 'selenium'.

有什么想法吗?谢谢。

【问题讨论】:

  • 您是否安装了 Selenium?尝试this post中的一些故障排除步骤
  • from Selenium import webdriver 大写很重要。为什么要使用大写字母S
  • @JohnGordon 很高兴指出这一点。我抓住了错误的回溯,因为这是我第一次编写代码时注意到的错误。这是正确大写的当前错误:Traceback (most recent call last): File "C:\Users\gvasquez\Scripts\viaUpdate.py", line 2, in &lt;module&gt; from selenium import webdriver ModuleNotFoundError: No module named 'selenium'
  • 你用什么命令来运行 Python shell,你用什么命令来运行脚本?
  • @GrahamVasquez 请使用正确的回溯更新您的问题

标签: python selenium


【解决方案1】:

好吧,所以我觉得自己很笨,但看起来我所要做的就是在文件名之前使用 python 命令运行它:

PS C:\User\username\scripts&gt; python viaUpdate.py

而不是PS C:\User\username\scripts&gt; viaUpdate.py

感谢您的帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2016-03-20
    • 2019-04-23
    • 1970-01-01
    • 2015-09-11
    相关资源
    最近更新 更多