大家好,又见面了,我是你们的朋友全栈君。
在windows下,可以使用pyinstaller打包python程序为exe可执行程序。
在cmd命令行窗口运行以下命令安装pyinstaller
pip install pyinstaller
在python程序所在目录,执行以下命令
# 切换到指定目录
cd /d path
# 正常打包命令
pyinstaller -F -w -i ico_path xxx.py
打包完成后,在对应目录会出现build和dist文件夹,exe文件就出现在dist文件夹,直接运行即可。
以我的chromedriver为例
打包生成exe文件后,依赖的文件还有chromedriver和谷歌浏览器(还需要版本一致)
所以在生成exe文件后,还需要将chromedriver和对应的谷歌浏览器版本一起
改为安装pyinstaller
因为你开了进程,需要在main后面添加一句
multiprocessing.freeze_support()
我的目录是
C:\Users\45906\AppData\Local\Programs\Python\Python37\Lib\site-packages\selenium\webdriver\common\service.py
将其文件中的75行修改
def start(self):
"""
Starts the Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file,
stderr=self.log_file,
#修改前
#stdin=PIPE)
#修改后
stdin=PIPE,creationflags=134217728)
这里注意,是chromedriver的命令行黑框,并不是window本身的命令行,windows的黑框在你打包的时候添加-w即可
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/131113.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有