首页 > 解决方案 > 为什么我会收到这个奇怪的 Python 错误?OSError:无法打开文件(未找到文件签名)

问题描述

我在 Miniconda 中使用 Python 脚本来运行使用名为 gprMax 的软件的模拟,这是一个 conda 环境。脚本运行良好,我得到了所需的输出,但是当我尝试分析输出时,出现以下错误:

OSError: Unable to open file (file signature not found)

我在错误之前在 Miniconda 中运行的代码是:

python -m tools.plot_Ascan path_To_file/filename

我在 Miniconda 中使用的脚本是:

import numpy as np

n = 0
x_max = 500
y_max = 250

v1 = 0.02
v2 = 0.17
v3 = 0.27
v4 = 0.50
v5 = 0.04
for x1 in range(0, x_max-1):
    for y1 in range(0, y_max-1):
        w = np.random.random()
        xx1 = x1*0.002
        yy1 = y1*0.002
        
        if w < v1:
            print("#box: {} {} {} {} {} {} ilm".format(xx1, yy1, 0, xx1+0.002, yy1+0.002, 0.002))
        elif w > v1 and w < v1+v2:
            print("#box: {} {} {} {} {} {} oliv".format(xx1, yy1, 0, xx1+0.002, yy1+0.002, 0.002))
        elif w > v1+v2 and w < v3:
            print("#box: {} {} {} {} {} {} pyr".format(xx1, yy1, 0, xx1+0.002, yy1+0.002, 0.002))
        elif w > v3 and w < v3+v4:
            print("#box: {} {} {} {} {} {} plag".format(xx1, yy1, 0, xx1+0.002, yy1+0.002, 0.002))
        else:
            print("#box: {} {} {} {} {} {} free_space".format(xx1, yy1, 0, xx1+0.002, yy1+0.002, 0.002))

就像我说的,脚本在 Miniconda 中运行良好,但 conda 似乎对 h5py 文件有问题:

  File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
  File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
  File "h5py\h5f.pyx", line 88, in h5py.h5f.open
OSError: Unable to open file (file signature not found)

标签: pythonminicondaoserror

解决方案


推荐阅读