python:[WinError 2]系统找不到指定的文件

时间:2018-06-08 06:43:05

标签: python python-3.x subprocess popen file-not-found

我面临一个相当奇怪的问题。我试图在python脚本中运行.js脚本。在我的.js脚本中,我将.pdf转换为json,然后在.py脚本中调用此.js脚本,将此json转换为.xlsx。

但是使用Popen执行.js脚本时会出现错误:" [WinError 2]系统无法找到指定的文件"。 我现在已经将错误位置重新检查了近10次。我也检查了cwd是否正确。 除了这个错误,一切都已到位。请帮我。 :(

import pandas as pd
from subprocess import Popen, PIPE
import os

cwd = os.getcwd()
bankType = "parsePmc"
parser_path = os.path.join(cwd, "parse_pmc_bank_pdf.js")
input_file_path = os.path.join(cwd, "bs.pdf")
output_file_path = os.path.join(cwd, "bs_excel.xlsx")
print(parser_path)
print(input_file_path)
print(output_file_path)
#parser_path = parser_path.replace("\\","\\\\") #(Even this doesn't work.)
print(parser_path)
args = ["node", parser_path, input_file_path, output_file_path] #I've even checked it using with str() for the paths.
print(os.getcwd())
p = Popen(args, stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
print(stdout)
if bool(stderr):
    print(stderr)
else:
    df = pd.read_json(output_file_path)
    if df.empty:
        print("EMPTY XLSX")
    else:
        df.to_excel(output_file_path, sheet_name='Raw')

[Error:] ---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-40-e3dffdd7e5db> in <module>()
      1 args = ["node", str(parser_path)]
      2 print(os.getcwd())
----> 3 p = Popen(args, stdout=PIPE, stderr=PIPE)
      4 stdout, stderr = p.communicate()
      5 print(stdout)

C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    705                                 c2pread, c2pwrite,
    706                                 errread, errwrite,
--> 707                                 restore_signals, start_new_session)
    708         except:
    709             # Cleanup if the child failed starting.

C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
    988                                          env,
    989                                          cwd,
--> 990                                          startupinfo)
    991             finally:
    992                 # Child is launched. Close the parent's copy of those 
    pipe

    FileNotFoundError: [WinError 2] The system cannot find the file specified

0 个答案:

没有答案