Packaging binaries for python scripts on macos so they are added to path

Viewed 37

TL;DR

Outside of specifying include_package_data=True and a manifest.in file, what are the procedures for including, and invoking binaries in a python package?

Background

So I have a project that I need to use an included binary from (Chrome WebDriver). Currently I have a manifest.in file that looks like this:

...
include utilities/webdriver_binaries/chromedriver_win.exe
include utilities/webdriver_binaries/chromedriver_mac
...

I am using Selenium and want to package the chromedriver with the installation. On windows I can just use:

browser = webdriver.Chrome(f"{os.path.dirname(__file__)}{os.sep}webdriver_binaries{os.sep}chromedriver_win.exe")

and it works perfectly.

On MacOS however I have tried dozens of approaches including this:

for path in sys.path:
    for root, dirs, files in os.walk(path):
        for name in dirs:
            if "webdriver_binaries" in name and os.path.isdir(os.path.abspath(name)):
                browser_path = f"{os.path.abspath(name)}{os.sep}chromedriver_mac"
                print(f"Trying to instantiate browser from {browser_path}")
                browser = webdriver.Chrome(browser_path)

sys.path seems to have directories called webdriver_binaries (specifically in /Library/Frameworks/Python.Frameworks/Versions/3.8/lib/python3.8/site-packages/webdriver_binaries) but when I try to cd into them they don't exist.

0 Answers
Related