您可以在pyinstaller的帮助下完成此操作:以下是在Windows上可以使用的解决方案,但是pyinstaller表示它也可以在Mac
OS上使用。
步骤如下:
- 打开命令提示符
- 在存在脚本的cmd中转到项目路径
- 键入pyinstaller scriptname.spec scriptname.py(如果在屏幕上出现提示,请输入y / yes)。
- 构建将位于“项目路径” dist scriptname
请注意,传递参数时,您需要在scriptname.spec中提供chromedriver的详细信息
规格文件的样本内容:
# -*- mode: python -*-block_cipher = Nonea = Analysis(['scriptname.py'], pathex=['Pathofproject'], binaries=[('C:\Python27\chromedriver.exe', '**.\selenium\webdriver**')], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher)pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)exe = EXE(pyz, a.scripts, exclude_binaries=True, name='createEVIPOrg_Automation_new', debug=False, strip=False, upx=True, console=True )coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name='**scriptname**')您需要更新脚本名称,脚本所在的项目路径,spec文件中chromedriver的路径



