[英]Python - pyinstaller : Read path file inside script to use in pyinstaller
I have script and work fine but after executable script by pyinstaller the scripte can't able to read file chromedriver.exe:我有脚本并且工作正常,但是在 pyinstaller 执行脚本后,脚本无法读取文件 chromedriver.exe:
This is the module code:这是模块代码:
fulpath of data.py
is: app\Resources\Data.py # the name app is root of script data.py 的data.py
是:app\Resources\Data.py # 名称 app 是脚本的根目录
name module data.py
:名称模块data.py
:
class General():
chrome_path = "drivers\\chrome\\chromedriver.exe"
CHROME = chrome_path
I use CHROME function in another module to run script.我在另一个模块中使用 CHROME function 来运行脚本。
Full path of chromedriver.exe
is: app\drivers\chrome\chromedriver.exe # the name app is root of script. chromedriver.exe
的完整路径是:app\drivers\chrome\chromedriver.exe # app 是脚本的根目录。
this is the app.spec:这是 app.spec:
block_cipher = None
added_files = [
('driver/chrome/chromedriver.exe','driver/chrome/')
]
a = Analysis(['app.py'],
pathex=['C:\\Users\\JOHN\\Desktop\\project'],
binaries=[],
datas=added_files,
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='app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
uac_admin=True,
icon='data\\image\\icon.ico')
How can I change path to compatible by pyinstaller如何通过 pyinstaller 将路径更改为兼容
When you call pyinstaller to build the executable, you can use --add-data "drivers/chrome/chromedriver.exe;drivers/chrome"
as a flag to add whatever you want to the build, as seen here .当您调用 pyinstaller 来构建可执行文件时,您可以使用--add-data "drivers/chrome/chromedriver.exe;drivers/chrome"
作为标志来添加您想要的任何内容到构建中,如此处所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.