I was looking at this excellent answer and copied the code for MacOS (top of answer, also reproduced below for convenience).
import os    # Code from answer linked above
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver
# path to the firefox binary inside the Tor package
binary = '/Applications/TorBrowser.app/Contents/MacOS/firefox'
if os.path.exists(binary) is False:
    raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
browser = None
def get_browser(binary=None):
    global browser  
    # only one instance of a browser opens, remove global for multiple instances
    if not browser: 
        browser = webdriver.Firefox(firefox_binary=binary)
    return browser
if __name__ == "__main__":
    browser = get_browser(binary=firefox_binary)
    urls = (
        ('tor browser check', 'https://check.torproject.org/'),
        ('ip checker', 'http://icanhazip.com')
    )
    for url_name, url in urls:
        print "getting", url_name, "at", url
        browser.get(url)
I keep getting the following error.
Traceback (most recent call last):
  File "torselenium.py", line 22, in <module>
    browser = get_browser(binary=firefox_binary)
  File "torselenium.py", line 18, in get_browser
    browser = webdriver.Firefox(firefox_binary=binary)
  File "/Users/user/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
    self.service.start()
  File "/Users/user/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 
This error is very similar to the error described in this question, where the recomendation is to set a firefox_binary path. Yet I have already done this and verified (verification proof below) that there is a firefox binary at that path.
$ ls /Applications/TorBrowser.app/Contents/MacOS/firefox
/Applications/TorBrowser.app/Contents/MacOS/firefox
In fact, if I set the binary path (line 7) to '~/Applications/TorBrowser.app/Contents/MacOS/firefox', it gives me the ValueError, so there is definitely a binary there.
I also checked if I have execute permissions, which I do and I tried changing browser from a global to local variable, to no help.
How can I resolve this error?
 
     
    