简体   繁体   English

使用 netCDF4 python 模块时出错

[英]Error using netCDF4 python module

I am using netCDF4 and python 3.4.我正在使用 netCDF4 和 python 3.4。

I run the following line of code in order to start writing a new netCDF file that I will be filling with data later in my code following netcdf4 documentation.我运行以下代码行以开始编写一个新的 netCDF 文件,稍后我将按照 netcdf4 文档在我的代码中填充数据。 I however keep getting this error...但是,我不断收到此错误...

File "netCDF4.pyx", line 1466, in netCDF4.Dataset.__init__ (netCDF4.c:19692) RuntimeError: Permission denied文件“netCDF4.pyx”,第 1466 行,在 netCDF4.Dataset.__init__ (netCDF4.c:19692) RuntimeError: Permission denied

from netCDF4 import Dataset
rootgrp = Dataset('test.nc', 'w', format='NETCDF4')

Any help will be most appreciated.任何帮助将不胜感激。

The "Permission denied" part of the error leads me to believe you don't have permissions to write to the current directory (wherever you are when you run your script).错误的“权限被拒绝”部分使我相信您没有写入当前目录的权限(无论您在何处运行脚本)。

Check your permissions and/or try giving a full path to put the file in a directory you know you can write to.检查您的权限和/或尝试提供完整路径以将文件放入您知道可以写入的目录中。

dataset.close()数据集.close()

or close ide and delete file 'netCDF4.pyx'或关闭ide并删除文件“netCDF4.pyx”

maybe a file exist there, so can't write it.也许那里存在一个文件,所以不能写它。

In my case, this error arises when I am running python by crontab.就我而言,当我通过 crontab 运行 python 时会出现此错误。

The solution is to add following line at the beginning of crontab file.解决方案是在 crontab 文件的开头添加以下行。

HDF5_USE_FILE_LOCKING=FALSE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM