名称“netCDF4”未定义 - RStudio 中的 python

问题描述

我最近开始研究使用 Miniconda 和库 reticulate 在 RStudio 中实现的 Python 3.6。

我已经安装了我需要使用的所有软件包 reticulate::py_install('name of the packages')

当我尝试导入一些 .nc 数据时:

import numpy as np
import pandas as pd
import cartopy as cp
from cartopy import crs as ccrs,feature as cfeature
import matplotlib.pyplot as plt
import xarray as xr
import openpyxl
import netCDF4

#%%
adt = xr.open_dataset("G:/Research/ADT.nc")

我收到此错误

NameError: name 'netCDF4' 未定义

我研究了可能的解决方案,例如: netCDF4 import not being found by Python 但我已经安装了软件包 netCDF4xarray 作为其他软件包,它们没有出现任何问题(到目前为止)

解决方法

我在 Jupiter Notebook 中遇到了这个错误,但随后我重新启动了内核并再次运行,一切正常。我使用 conda 安装了 netcdf4。