Jupyter Server上的读/写访问问题Python

问题描述 投票:0回答:1

我正在远程使用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
python pandas file-permissions jupyter
1个回答
0
投票
  • 我为此遇到了类似的问题。
  • 事实证明,作为当前用户,我正在运行文件的权限不足,无法写入。
  • 我与root用户运行了相同的脚本,并且有效。

[注:这很晚了,不是对OP的问题的答案,而是对我来说类似的情况,并且为我写了可行的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.