Is there a way to associate a binary (e.g. chrome file) with a single / exe file application compiled with Pyinstaller?

As noted in the answer to my question here , setting the path to the chromedriver in binariesthe specification file Pyinstaller ( binaries=[('/usr/bin/chromedriver', './selenium/webdriver')]) had no effect (if it was not installed incorrectly). That is, access to the chrome transmission is carried out as long as it is in PATH (/ usr / bin in this case). My question is about the possibility of linking the chronograph in the background, so it should not be manually installed on another machine.

0
source share
1 answer

I successfully linked the chrome recorder to pyinstaller (although, unfortunately, my virusscanner noted it after running exe, but this is another problem)

I think your problem is that you did not specify the correct path to the webdriver in the script (using the executable_path keyword). Also, I included chromedriver in the data file, although I'm not sure if that matters.

Here is my example.

sel_ex.py:

from selenium import webdriver

import os, sys, inspect     # http://stackoverflow.com/questions/279237/import-a-module-from-a-relative-path
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe() ))[0]))

def init_driver():
    chromedriver = os.path.join(current_folder,"chromedriver.exe")
    # via this way, you explicitly let Chrome know where to find 
    # the webdriver.
    driver = webdriver.Chrome(executable_path = chromedriver) 
    return driver

if __name__ == "__main__":
    driver = init_driver()
    driver.get("http://www.imdb.com/")

sel_ex.spec:

....
binaries=[],
datas=[("chromedriver.exe",".")],
....

Thus, the chrome record was stored in the main folder, although it does not matter where it is stored if the correct script path is through the executable_path keyword

disclaimer: -I have not used the parameters of a single file, but this should not change. -my OS are windows

+3
source

Source: https://habr.com/ru/post/1655012/


All Articles