我正在尝试使用pyinstaller打包我的应用程序,以便其他人可以使用它而不必下载所有其他文件等。目前,我的脚本使用以下代码启动selenium chromedriver:
import os, inspect
current_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe() ))[0]))
chromedriver = os.path.join(current_folder, "chromedriver")
browser = webdriver.Chrome(chromedriver, options=chrome_options )
我正在使用以下代码创建一个规范文件:
pyi-makespec --onefile check_in_final.py
然后我在规范文件中编辑二进制文件:
binaries=[('/Users/Vetle/Python/Scripts/Wiredelta_Timer/Final/chromedriver', '.')],
然后我使用以下命令创建文件:
pyinstaller check_in_final.spec
并在尝试启动我新创建的打包应用程序时得到错误:
Traceback (most recent call last):
File "site-packages/selenium/webdriver/common/service.py", line 76, in start
File "subprocess.py", line 769, in __init__
File "subprocess.py", line 1516, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: '/Users/Vetle/chromedriver': '/Users/Vetle/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "check_in_final.py", line 248, in <module>
File "check_in_final.py", line 223, in login_timer
File "site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
File "site-packages/selenium/webdriver/common/service.py", line 83, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
[21745] Failed to execute script check_in_final
我尝试将chromedriver文件放在主文件夹中,并且可以正常工作。但是,我不希望文件存储在其中,我的应用程序中的文本文件也会发生这种情况-我可以通过任何方式将它们存储在应用程序文件中或在其中创建新的目录文件夹吗?