天天看點

Python FileNotFoundError: [WinError 2] 系統找不到指定的檔案

錯誤描述

Traceback (most recent call last):
  File "D:\Python\Python36-32\lib\site-packages\selenium-3.4.3-py3.6.egg\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "D:\Python\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "D:\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系統找不到指定的檔案。
           

問題分析

後來在stackoverflow上找到如下解決辦法:

在Windows 在子程序中使用echo,需要設定

shell =True

,因為 echo 不是單獨的指令,而是Window CMD 内置的指令

并且,需要注意,隻有在絕對需要的情況下才使用shell=True

在lib檔案夾中找到

subprocess.py

  • 搜尋

    class Popen(object):

  • __init__

    中的

    shell=False

    修改為

    shell=True