Selenium in Python on Mac - Geckodriver executable needs to be in PATH(Mac 上 Python 中的 Selenium - Geckodriver 可执行文件需要在 PATH 中)
问题描述
我是编程新手,大约 2 个月前开始使用 Python,现在正在阅读 Sweigart 的 Automate the Boring Stuff with Python text.我正在使用 Spyder 3 并且已经安装了 selenium 模块和 Firefox 浏览器.我在python文件中使用了以下代码
I'm new to programming and started with Python about 2 months ago and am going over Sweigart's Automate the Boring Stuff with Python text. I'm using Spyder 3 and already installed the selenium module and the Firefox browser. I used the following code in python file
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://inventwithpython.com')
我收到此错误:
Message: 'geckodriver' executable needs to be in PATH.
除了进入终端并使用安装它之外,我还下载了 geckodriver.exe
I've downloaded geckodriver.exe in addition to going into terminal and installing it using
brew install geckodriver
奇怪的是,如果我进入终端并输入python",然后将代码放入,它可以工作,但当我在 Spyder 中运行文件时却不行.我需要将 geckodriver.exe 文件放在哪里才能正常工作?我尝试将它放在各种文件夹中(与 python 文件相同的文件夹,与 webdriver 文件相同的文件夹,在用户 bin 中,等等),但我得到了同样的错误
Oddly enough, if I go into terminal and type "python" and then put the code in, it works, but not when I run the file in Spyder. Where do I need to put the geckodriver.exe file for it to work? I've tried putting it in various folders (same folder as the python file, same folder as the webdriver file, in the user bin, and so on) but I get the same error
我查看了类似的问题,但似乎找不到有效的方法.我也尝试过使用 Chrome,但使用 chromedriver 时出现同样的错误.
I've looked at similar questions but can't seem to find something that works. I've also tried with Chrome but I get the same error but with chromedriver.
which geckodriver
产生 /usr/local/bin/geckodriver
我也在 Mac 上,所以文件路径对我来说比在 Windows 上要困难一些.
I'm also on a Mac, so file paths are a little more difficult for me than on windows.
推荐答案
已解决:我将 geckodriver exe 放在/Users/sethkillian/anaconda/bin 中,现在它可以在 Spyder 上正常运行.感谢您的帮助!
SOLVED: I placed the geckodriver exe in /Users/sethkillian/anaconda/bin and now it works from Spyder with no problem. Thanks for the help!
这篇关于Mac 上 Python 中的 Selenium - Geckodriver 可执行文件需要在 PATH 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Mac 上 Python 中的 Selenium - Geckodriver 可执行文件需要在 PATH 中


基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01