【发布时间】:2017-09-29 19:06:52
【问题描述】:
我编写了一些在 Linux 机器上运行良好但在 Windows 上无法运行的代码。
import subprocess
import pandas as pd
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
def zgrep_data(f, string='', index='TIMESTAMP'):
if string == '':
out = subprocess.check_output(['zgrep', string, f])
grep_data = StringIO(out)
data= pd.read_csv(grep_data, sep=',', header=0)
else:
col_out = subprocess.check_output(['zgrep', index, f])
col_data = StringIO(col_out)
columns = list(pd.read_csv(col_data, sep=','))
out = subprocess.check_output(['zgrep', string, f])
grep_data = StringIO(out)
data= pd.read_csv(grep_data, sep=',',names=columns, header=None)
return data.set_index(index).reset_index()
我收到一个错误: FileNotFoundError: [WinError 2] 系统找不到指定的文件
当我用 os.path.exists(file_path) 检查它时,它返回 true。任何有关如何修改此代码以使其在 Python 2 和 3 以及 Windows 和 Linux 上运行的建议都将不胜感激。
【问题讨论】:
-
zgrep不在您的路径中。这不是标准的 windows 命令,所以你必须找到一个 windows 版本并安装它......这是对错误的唯一解释。你在检查哪个文件?file_path是什么? -
文件在我的c盘。 C:/Users/Chris/Documents/massivefile.csv
-
所以文件路径在函数中为 f
-
你看过我的第一条评论了吗?这与您的数据文件无关。
标签: python linux subprocess zgrep