【问题标题】:Installed selenium using pip worked but Python throws an error使用 pip 安装 selenium 工作但 Python 抛出错误
【发布时间】:2019-05-19 11:12:18
【问题描述】:

我是 python selenium 的新手,偶然发现了一个问题。

我使用 pip sudo pip install selenium 安装了 selenium,它运行良好。 但是当我尝试在我的项目中使用 from selenium import WebDriver 导入 selenium 时,Python 会抛出错误。

我已经安装了 python 2.7 并更新到了 python 3.7.3。 我检查了 pip 安装 selenium 的地方,它在library/Python/python2.7。但是没有文件夹 3.7.3 我可以在其中拖放这些文件。

Betriebs 系统: MacOS Mojave

Python 代码:

from selenium import webdriver
driver = webdriver.Chrome('driver/chromedriver')
driver.get('https://www.google.com/')

Python Fehlermeldung:

Traceback (most recent call last):
  File "/Users/christophriepe/Desktop/Integrationstest 
Trainopedia/Integrationstest Trainopedia.py", line 1, in <module>
  from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'

我想这与我安装的两个版本的 python 有关。但是我迷路了,不知道如何解决这整件事:(

提前谢谢你们。

【问题讨论】:

  • 尝试sudo pip3 install selenium - 如果您没有 pip3,请参阅 https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3 - 可能您的安装失败了
  • 如果你安装了两条蟒蛇,那么你应该有pythonpython2python3,甚至是python2.7python3.7。与pippip2pip2.7pip3pip3.7 相同。在终端中写入pip 并按tab 以查看所有以pip 开头的命令。 pythontab 也是如此。
  • 如果您没有pip3,那么您可以使用python3 -m pip install ...
  • 您是否确保将 selenium 包添加到 File>Settings>Project:name_of_project > Project Interpreter 下的项目中?

标签: python python-3.x selenium google-chrome


【解决方案1】:

为 Python 2 安装 selenium:

python -m pip install selenium

为 Python 3 安装 selenium:

python3 -m pip install selenium

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-29
    • 2022-12-03
    • 2013-11-07
    • 2016-12-13
    • 2016-04-28
    • 2014-06-10
    相关资源
    最近更新 更多