问题描述
我是编程新手,大约 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 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!