【问题标题】:Windows operating system unable to open file names that works on linuxWindows 操作系统无法打开适用于 linux 的文件名
【发布时间】:2018-08-12 04:10:41
【问题描述】:

我正在 Linux 上开发一个小型 Python 应用程序,其中代码在系统 Python3 和 Anaconda Python3 解释器上运行良好。但是,当我在 Anaconda/Windows 上运行它时,我得到了这个回溯:

Traceback (most recent call last):
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\tkinter\__init__.py"
, line 1699, in __call__
    return self.func(*args)
  File "./dataView.py", line 312, in doChop
    self.DA.chop()
  File "C:\Users\<redacted>\DataAnalyser.py", line 212, in chop
    self.df.to_hdf( filename, mode='w', key=hdfKey, data_columns = view )
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas
\core\generic.py", line 1471, in to_hdf
    return pytables.to_hdf(path_or_buf, key, self, **kwargs)
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas
\io\pytables.py", line 280, in to_hdf
    complib=complib) as store:
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas
\io\pytables.py", line 467, in __init__
    self.open(mode=mode, **kwargs)
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas
\io\pytables.py", line 580, in open
    self._handle = tables.open_file(self._path, self._mode, **kwargs)
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\tables
\file.py", line 320, in open_file
    return File(filename, mode, title, root_uep, filters, **kwargs)
  File "C:\Users\<redacted>\AppData\Local\Continuum\anaconda3\lib\site-packages\tables
\file.py", line 784, in __init__
    self._g_new(filename, mode, **params)
  File "tables\hdf5extension.pyx", line 487, in tables.hdf5extension.File._g_new

tables.exceptions.HDF5ExtError: HDF5 error back trace

  File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5F.c", line
491, in H5Fcreate
    unable to create file
  File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5Fint.c", li
ne 1247, in H5F_open
    unable to open file: time = Wed Feb 28 18:26:31 2018
, name = 'chop_x:0:49.hdf5', tent_flags = 13
  File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5FD.c", line
 809, in H5FD_open
    open failed
  File "C:\Users\builder\mc3\conda-bld\hdf5_1506030377716\work\src\H5FDsec2.c",
line 346, in H5FD_sec2_open
    unable to open file: name = 'chop_x:0:49.hdf5', errno = 22, error message =
'Invalid argument', flags = 13, o_flags = 302

End of HDF5 error back trace

Unable to open/create file 'chop_x:0:49.hdf5'

我尝试在 Anaconda/Win ipython3 中手动写入一个完全相同名称的文件,该文件也运行良好。我还尝试将名称更改为一个简单的字符串,这很有效,这表明我传递的文件名值确实有问题,它是用 str.format() 构造的。另一方面,当我做df.to_hdf('chop_x:0:49.hdf5', 'w', 'chop') 时,它工作正常。如何查看我传递的参数有什么问题?你认为是另一个参数的问题吗?

【问题讨论】:

  • 你看到unable to create file .... unable to open file: time = Wed Feb 28 18:26:31 2018 , name = 'chop_x:0:49.hdf5' ..... open failed (bexause it could not be created) - 是吗?
  • 糟糕,我错了。我没有正确测试。帕特里克是正确的。谢谢!

标签: windows python-3.x file anaconda hdf5


【解决方案1】:

不同的操作系统对路径和文件名中允许的字符有不同的限制。

尝试在 Windows 资源管理器中创建一个带有: 的文件名,你就会明白为什么它不起作用了。

Naming Files, Paths, and Namespaces

弃权:

< (less than)
> (greater than) 
: (colon)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)

整数值零,有时称为 ASCII NUL 字符。 整数表示范围为 1 的字符 到 31,除了这些字符的备用数据流 是允许的。

(摘自以上链接,还有更多内容,请阅读。)

【讨论】:

  • 哦,好主意,但我想我可以排除这种可能性。在 iPython3 中,我尝试使用 df.to_hdf('chop_x:0:49.hdf5', 'w', 'chop') 手动完成,并且确实有效。因此,从所有其他方面来看,该字符串似乎都很好。
  • @PorcelainMouse 在 Windows 上,您不能拥有这样命名的文件。它被操作系统禁止。在linux上它可能工作。一旦数据帧被持久化到文件系统,操作系统就会抛出一个曲线球(异常)并且它不会工作。
  • 糟糕,我的错误。你说的对。我记错了我的测试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 1970-01-01
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多