PyNio读取数据出现file format not supported or file is corrupted

本文介绍了在Windows的Ubuntu子系统中如何使用conda安装PyNIO和PyNGL,并解决遇到的'file format not supported or file is corrupted'错误。通过修改文件权限成功读取数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  ncl 转到python平台已经有一段时间了,从安装到读文件,真的是步步艰辛哪!摸索许久,也终于有了点心得,以前在这个平台得到许多帮助,现在作为第一批吃螃蟹的人(不是第一批也算比较早吧!),我也来贡献一下自己小小的力量吧!

1、就目前来说,PyNIOn ,PyNGL这两个包只能安装在linux系统下,与python能不能安装在windows下无关,即使是VS下的powershell即使有着类似linux的外壳,也是不可以滴。

2、对于windows系统来说,可以安装在Ubuntu子系统中(子系统怎么装的就不用我废话了吧),安装命令是:
conda create -n pyn_env -c conda-forge pynio pyngl
其中conda是一个包管理器,可以创建一个python的虚拟环境,然后将各个工具包打包进去,create就是创建(当你已经有了一个python虚拟环境,需要往里面安装的时候,只需把create换为install即可),-n也可以写成–name,意思是指明虚拟环境的名字,pyn_env就是我给这个虚拟环境起的名字,-c也可以写成–channel,是指从anaconda的各个通道里下载所需的包,conda-forge是anaconda下其中一个通道(说实话,我也并不是很明白二者的含义,我的理解是channel是网址,conda-forge 是下一级的块),pynio和pyngl是需要安装的包,同样你还可以在后面空格添加python,netcdf,scipy,xarray等可能用到的包,可以通过python=3的方式来指明安装的版本。

3、安装成功以后,可以通过conda env list来看一下虚拟环境的情况,如果你这是第一次用conda创建环境的话,应该只有两个,一个是base这个是一有conda就默认自带的,另外一个是新建的pyn_env(具体看你给它起什么名字了),如果你之前用conda装过ncl应该还会有一个类似于ncl_table的环境。

4、如果在list中有pyn_env这个环境了,就可以通过conda activate pyn_env(或source activate pyn_env,如果是wind

报错了: FAILED [100%] test_len.py:9 (TestWms.test_02) self = <case.test_len.TestWms object at 0x000002902917B2B0> def test_02(self): > datas = xfile.read(r"C:\Users\shuohan\Desktop\gaoliu-1\仓库删除模块接口用例.xlsx").excel_to_dict(sheet=1) test_len.py:11: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ..\..\myvenv\lib\site-packages\xToolkit\xfile\dispose\dispose.py:67: in excel_to_dict workbook = xlrd.open_workbook(excel_file) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ filename = 'C:\\Users\\shuohan\\Desktop\\gaoliu-1\\仓库删除模块接口用例.xlsx' logfile = <_io.TextIOWrapper name='<tempfile._TemporaryFileWrapper object at 0x00000290000E2940>' mode='r+' encoding='utf-8'> verbosity = 0, use_mmap = True, file_contents = None, encoding_override = None formatting_info = False, on_demand = False, ragged_rows = False ignore_workbook_corruption = False def open_workbook(filename=None, logfile=sys.stdout, verbosity=0, use_mmap=True, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False, ignore_workbook_corruption=False ): """ Open a spreadsheet file for data extraction. :param filename: The path to the spreadsheet file to be opened. :param logfile: An open file to which messages and diagnostics are written. :param verbosity: Increases the volume of trace material written to the logfile. :param use_mmap: Whether to use the mmap module is determined heuristically. Use this arg to override the result. Current heuristic: mmap is used if it exists. :param file_contents: A string or an :class:`mmap.mmap` object or some other behave-alike object. If ``file_contents`` is supplied, ``filename`` will not be used, except (possibly) in messages. :param encoding_override: Used to overcome missing or bad codepage information in older-version files. See :doc:`unicode`. :param formatting_info: The default is ``False``, which saves memory. In this case, "Blank" cells, which are those with their own formatting information but no data, are treated as empty by ignoring the file's ``BLANK`` and ``MULBLANK`` records. This cuts off any bottom or right "margin" of rows of empty or blank cells. Only :meth:`~xlrd.sheet.Sheet.cell_value` and :meth:`~xlrd.sheet.Sheet.cell_type` are available. When ``True``, formatting information will be read from the spreadsheet file. This provides all cells, including empty and blank cells. Formatting information is available for each cell. Note that this will raise a NotImplementedError when used with an xlsx file. :param on_demand: Governs whether sheets are all loaded initially or when demanded by the caller. See :doc:`on_demand`. :param ragged_rows: The default of ``False`` means all rows are padded out with empty cells so that all rows have the same size as found in :attr:`~xlrd.sheet.Sheet.ncols`. ``True`` means that there are no empty cells at the ends of rows. This can result in substantial memory savings if rows are of widely varying sizes. See also the :meth:`~xlrd.sheet.Sheet.row_len` method. :param ignore_workbook_corruption: This option allows to read corrupted workbooks. When ``False`` you may face CompDocError: Workbook corruption. When ``True`` that exception will be ignored. :returns: An instance of the :class:`~xlrd.book.Book` class. """ file_format = inspect_format(filename, file_contents) # We have to let unknown file formats pass through here, as some ancient # files that xlrd can parse don't start with the expected signature. if file_format and file_format != 'xls': > raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') E xlrd.biffh.XLRDError: Excel xlsx file; not supported ..\..\myvenv\lib\site-packages\xlrd\__init__.py:170: XLRDError
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值