我在Python 3创建一个程序,我想用户打开一个URL指定的Web浏览器application.I使用已经试过subprocess.Popen([application, URL])
,但它提出了一个FileNotFoundError
。任何帮助是极大的赞赏。
编辑:我忘了提到我正在使用Windows 10,这是我收到的错误消息的副本:
Traceback (most recent call last):
File "C:\Users\[Name]\Desktop\AI.py", line 221, in <module>
subprocess.Popen(["google-chrome", "www.google.co.uk/"])
File "C:\Python34\lib\subprocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
EDIT2:如果我尝试运行,这是我的结果subprocess.Popen(["start", "chrome", "www.example.com/"])
(如果我忽略了"start",
数组的一部分,则会出现相同的错误):
`Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
subprocess.Popen(["start", "chrome", "http://www.google.co.uk/"])
File "C:\Python34\lib\subprocess.py", line 859, in __init__ restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified`
import subprocess
subprocess.Popen([r"C:/Users/haral_000/AppData/Local/Google/Chrome/Application/chrome.exe", "example.com"])
字符串开头的'r'使其成为原始字符串,因此反斜杠不会被解释为转义符。
也许不是最优雅的解决方案,但是它可以工作。我转到“开始”菜单并搜索Chrome,右键单击并选择“打开文件位置”,然后查看快捷方式的属性以找到exe文件的实际位置。毫无疑问,此文件在您的其他位置。而且当然不在我的用户名之下。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句