- 近来需要在windows10下,需要使用python语言编程,启动html网页但是还得是google浏览器下打开的,我上网上查了一下,需要pip安装selenium包,我不想安装, 于是就使用了os.popen加cmd的start 命令,没想到还挺好用。代码如下:
import os
cmd_str = "start chrome.exe xxx/xxx.html
f = os.popen(cmd_str)
f.close()
前提是系统里安装了google浏览器啦。
2. 还有一个问题给我自己记录一下, windows下pyinstaller打包后的程序里面竟然使用如下命令,
import os
cmd_str = "python xxx/xxx.py
f = os.popen(cmd_str)
f.close()
有的电脑好使,有的不好使。我查了一下,竟然是
pyinstaller 下os.popen 里的python xxx.py这个文件不会一起被编译, 路径得是相对路径;
windows电脑下,Python没安装的话, cmd控制台里面python xxx.py有可能调用失败,当然pyinstaller打包了也还是不好使,叹气.jpg。
需要把这类文件也单独打包,
pyinstaller -D -W aaa.py
import os
# way-1 这个能调用就用这个
cmd_str = "xxx/aaa.exe" # 相对路径
# way-2 上边的调不起来就用这个
# cmd_str = "start xxx/aaa.exe" # 相对路径
f = os.popen(cmd_str)
f.close()
总结:
1. windows + python : os.popen + start + xxx.exe
2. windows + python + pyinstaller + os.popen: 得额外查看路径,和 额外打个包。