【发布时间】:2020-09-08 16:02:45
【问题描述】:
我正在尝试制作一个使用 selenium 和 webdriver 的网络抓取脚本的独立可执行文件,并且我希望能够将文件共享给其他用户,而无需他们手动安装 chromedriver 并指定其路径。
当我在同一目录中使用 chromedriver 运行可执行文件时,我在终端中得到以下输出:
Traceback (most recent call last):
File "site-packages/selenium/webdriver/common/service.py", line 76, in start
File "subprocess.py", line 707, in __init__
File "subprocess.py", line 1326, in _execute_child
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "excelRW.py", line 336, in <module>
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
在我的脚本中,这就是我初始化 webdriver 的内容:
driver = webdriver.Chrome()
我确实在这里找到了类似的问题/答案: Create a Python executable with chromedriver & Selenium
但我不确定如何在 MacOS 上进行这项工作;我在这里尝试了这个规范文件,但是当我运行 /dist/excelRW.py 时,它给了我与上面相同的输出:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['excelRW.py'],
pathex=['/Users/graememjehovich/Desktop/House Districting Script'],
binaries=[('/Users/graememjehovich/Desktop/House Districting Script/chromedriver', '**./selenium/webdriver**')],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='excelRW',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='**excelRW.py**')
【问题讨论】:
标签: python selenium selenium-webdriver selenium-chromedriver pyinstaller