我正在远程使用jupyter笔记本服务器,当我使用以下方式创建文件时:
file = open("test.txt","w") file.write("test") file.close()
所有内容都按预期工作,并且文件test.txt写入工作目录。我的问题出现了,试图使用pandas to_hfs命令:
data.to_hdf('raw_data.h5','raw_data_santodomingo',mode='w',format='f',data_columns=True)
我有以下错误:
Opening raw_data.h5 in read-only mode
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in open(self, mode, **kwargs)
586 try:
--> 587 self._handle = tables.open_file(self._path, self._mode, **kwargs)
588 except (IOError) as e: # pragma: no cover
/opt/conda/lib/python3.6/site-packages/tables/file.py in open_file(filename, mode, title, root_uep, filters, **kwargs)
319 # Finally, create the File instance, and return it
--> 320 return File(filename, mode, title, root_uep, filters, **kwargs)
321
/opt/conda/lib/python3.6/site-packages/tables/file.py in __init__(self, filename, mode, title, root_uep, filters, **kwargs)
783 # Now, it is time to initialize the File extension
--> 784 self._g_new(filename, mode, **params)
785
tables/hdf5extension.pyx in tables.hdf5extension.File._g_new()
/opt/conda/lib/python3.6/site-packages/tables/utils.py in check_file_access(filename, mode)
178 raise IOError("directory ``%s`` exists but it can not be "
--> 179 "written" % (parentname,))
180 elif mode == 'a':
OSError: directory ``.`` exists but it can not be written
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-182-479f2e98ea81> in <module>()
----> 1 pre_clean_data.to_hdf('raw_data.h5','raw_data_santodomingo',mode='w',format='f',data_columns=True)
/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py in to_hdf(self, path_or_buf, key, **kwargs)
1136
1137 from pandas.io import pytables
-> 1138 return pytables.to_hdf(path_or_buf, key, self, **kwargs)
1139
1140 def to_msgpack(self, path_or_buf=None, encoding='utf-8', **kwargs):
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in to_hdf(path_or_buf, key, value, mode, complevel, complib, append, **kwargs)
267 if isinstance(path_or_buf, string_types):
268 with HDFStore(path_or_buf, mode=mode, complevel=complevel,
--> 269 complib=complib) as store:
270 f(store)
271 else:
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in __init__(self, path, mode, complevel, complib, fletcher32, **kwargs)
446 self._fletcher32 = fletcher32
447 self._filters = None
--> 448 self.open(mode=mode, **kwargs)
449
450 @property
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in open(self, mode, **kwargs)
589 if 'can not be written' in str(e):
590 print('Opening %s in read-only mode' % self._path)
--> 591 self._handle = tables.open_file(self._path, 'r', **kwargs)
592 else:
593 raise
/opt/conda/lib/python3.6/site-packages/tables/file.py in open_file(filename, mode, title, root_uep, filters, **kwargs)
318
319 # Finally, create the File instance, and return it
--> 320 return File(filename, mode, title, root_uep, filters, **kwargs)
321
322
/opt/conda/lib/python3.6/site-packages/tables/file.py in __init__(self, filename, mode, title, root_uep, filters, **kwargs)
782
783 # Now, it is time to initialize the File extension
--> 784 self._g_new(filename, mode, **params)
785
786 # Check filters and set PyTables format version for new files.
tables/hdf5extension.pyx in tables.hdf5extension.File._g_new()
/opt/conda/lib/python3.6/site-packages/tables/utils.py in check_file_access(filename, mode)
154 # The file should be readable.
155 if not os.access(filename, os.F_OK):
--> 156 raise IOError("``%s`` does not exist" % (filename,))
157 if not os.path.isfile(filename):
158 raise IOError("``%s`` is not a regular file" % (filename,))
OSError: ``raw_data.h5`` does not exist
这些行似乎是相关的,并且使我认为写入许可是问题:
/opt/conda/lib/python3.6/site-packages/tables/utils.py in check_file_access(filename, mode)
154 # The file should be readable.
155 if not os.access(filename, os.F_OK):
--> 156 raise IOError("``%s`` does not exist" % (filename,))
157 if not os.path.isfile(filename):
158 raise IOError("``%s`` is not a regular file" % (filename,))
和
/opt/conda/lib/python3.6/site-packages/tables/utils.py in check_file_access(filename, mode)
154 # The file should be readable.
155 if not os.access(filename, os.F_OK):
--> 156 raise IOError("``%s`` does not exist" % (filename,))
157 if not os.path.isfile(filename):
158 raise IOError("``%s`` is not a regular file" % (filename,))
OSError: ``raw_data.h5`` does not exist
,这会让我感到困惑,因为我可以在工作目录中编写文本文件,如上所述。
所有的援助尝试。编辑:如果我使用完整的路径:/home/joyvan/work/raw_data.h5'我会收到不同的错误读数。
data.to_hdf('/home/joyvan/work/raw_data.h5','raw_data_santodomingo',mode='w',format='f',data_columns=True)
产生
OSError Traceback (most recent call last)
<ipython-input-185-de493145e6a7> in <module>()
----> 1 pre_clean_data.to_hdf('/home/joyvan/work/raw_data.h5','raw_data_santodomingo',mode='w',format='f',data_columns=True)
/opt/conda/lib/python3.6/site-packages/pandas/core/generic.py in to_hdf(self, path_or_buf, key, **kwargs)
1136
1137 from pandas.io import pytables
-> 1138 return pytables.to_hdf(path_or_buf, key, self, **kwargs)
1139
1140 def to_msgpack(self, path_or_buf=None, encoding='utf-8', **kwargs):
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in to_hdf(path_or_buf, key, value, mode, complevel, complib, append, **kwargs)
267 if isinstance(path_or_buf, string_types):
268 with HDFStore(path_or_buf, mode=mode, complevel=complevel,
--> 269 complib=complib) as store:
270 f(store)
271 else:
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in __init__(self, path, mode, complevel, complib, fletcher32, **kwargs)
446 self._fletcher32 = fletcher32
447 self._filters = None
--> 448 self.open(mode=mode, **kwargs)
449
450 @property
/opt/conda/lib/python3.6/site-packages/pandas/io/pytables.py in open(self, mode, **kwargs)
585
586 try:
--> 587 self._handle = tables.open_file(self._path, self._mode, **kwargs)
588 except (IOError) as e: # pragma: no cover
589 if 'can not be written' in str(e):
/opt/conda/lib/python3.6/site-packages/tables/file.py in open_file(filename, mode, title, root_uep, filters, **kwargs)
318
319 # Finally, create the File instance, and return it
--> 320 return File(filename, mode, title, root_uep, filters, **kwargs)
321
322
/opt/conda/lib/python3.6/site-packages/tables/file.py in __init__(self, filename, mode, title, root_uep, filters, **kwargs)
782
783 # Now, it is time to initialize the File extension
--> 784 self._g_new(filename, mode, **params)
785
786 # Check filters and set PyTables format version for new files.
tables/hdf5extension.pyx in tables.hdf5extension.File._g_new()
/opt/conda/lib/python3.6/site-packages/tables/utils.py in check_file_access(filename, mode)
172 parentname = '.'
173 if not os.access(parentname, os.F_OK):
--> 174 raise IOError("``%s`` does not exist" % (parentname,))
175 if not os.path.isdir(parentname):
176 raise IOError("``%s`` is not a directory" % (parentname,))
OSError: ``/home/joyvan/work`` does not exist
- 我遇到了类似的问题。
- 事实证明,作为当前用户,我正在运行文件没有足够的权限来写。
- 我与root用户一起运行了相同的脚本,并且它起作用。
注意:这是迟到的,不是对我的问题的答案,但对我来说类似的情况和对我有用的写作解决方案。