我正在尝试执行显示特定路径的文件格式的代码。
但是我收到了与指定路径相关的以下错误。在'C:\ Research \ LungCancerDetaction \ Preprocessing2.py'文件夹中执行的文件。
'input'文件夹位于路径C:\ Research \ input。
以下是编写的代码。
import numpy as np # Linear algebra
import pandas as pd # Data processing, CSV file I/O (e.g. pd.read_csv)
import skimage, os
from skimage.morphology import ball, disk, dilation, binary_erosion, remove_small_objects, erosion, closing, reconstruction, binary_closing
from skimage.measure import label,regionprops, perimeter
from skimage.morphology import binary_dilation, binary_opening
from skimage.filters import roberts, sobel
from skimage import measure, feature
from skimage.segmentation import clear_border
from skimage import data
from scipy import ndimage as ndi
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import dicom
import scipy.misc
import numpy as np
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory
import subprocess
print(subprocess.check_output(["ls", "../input"]).decode("utf8"))
但是我收到了错误,
Traceback (most recent call last):
File "C:/Research/LungCancerDetaction/Preprocessing2.py", line 22, in <module>
print(subprocess.check_output(["ls", "../input"]).decode("utf8"))
File "C:\Research\Python_installation\lib\subprocess.py", line 626, in check_output
**kwargs).stdout
File "C:\Research\Python_installation\lib\subprocess.py", line 693, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Research\Python_installation\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Research\Python_installation\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
如何找出错误?
答案 0 :(得分:0)
删除此行...
print(subprocess.check_output(["ls", "../input"]).decode("utf8"))
...而是使用它:
import os
print(os.listdir('../input'))