2016-10-24 3 views
0

я бегу следующие в окнах:Система не может найти указанный файл для check_output

from subprocess import check_output 
check_output(["dir", "D:/C_Drive/Desktop/Kaggle"]) 

я получил следующую проблему, «D:/C_Drive/Desktop/Kaggle» в настоящее время является папка на моем рабочем столе.

-- WindowsError        Traceback (most recent call last) <ipython-input-9-6f7efc3bbf8c> in <module>() 
    10 
    11 from subprocess import check_output 
---> 12 check_output(["dir", "D:/C_Drive/Desktop/Kaggle"]) 
    13 
    14 # Any results you write to the current directory are saved as output. 

C:\Program Files\Anaconda2\lib\subprocess.pyc in check_output(*popenargs, **kwargs) 
    565  if 'stdout' in kwargs: 
    566   raise ValueError('stdout argument not allowed, it will be overridden.') 
--> 567  process = Popen(stdout=PIPE, *popenargs, **kwargs) 
    568  output, unused_err = process.communicate() 
    569  retcode = process.poll() 

C:\Program Files\Anaconda2\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 
    709         p2cread, p2cwrite, 
    710         c2pread, c2pwrite, 
--> 711         errread, errwrite) 
    712   except Exception: 
    713    # Preserve original exception in case os.close raises. 

C:\Program Files\Anaconda2\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 
    957           env, 
    958           cwd, 
--> 959           startupinfo) 
    960    except pywintypes.error, e: 
    961     # Translate pywintypes.error to WindowsError, which is 

WindowsError: [Error 2] The system cannot find the file specified 
+0

Почему вы используете подпроцесс список файлов в каталоге? Использует ли 'os.listdir()' для этого пути? Вы пробовали какой-либо из родительских каталогов или одну и ту же команду в окне консоли? –

+0

Я только что выучил команду здесь https://www.kaggle.com/dvasyukova/expedia-hotel-recommendations/predict-hotel-type-with-pandas не уверен, почему он использует check_output, хотя – william007

+0

Возможный дубликат http: //stackoverflow.com/questions/3022013/windows-cant-find-the-file-on-subprocess-call – tripleee

ответ

0

добавить shell=True будет оштрафован

from subprocess 

import check_output print(check_output(["dir", "D:\\C_Drive\\Desktop\\Kaggle"],shell=True).decode("utf-8")) 

вдохновлен этой должности Windows can't find the file on subprocess.call()

+0

Я думаю, вы имеете в виду 'shell = True' –

Смежные вопросы