如何在 mac 上使用 python 读取 CDF 文件?

How to read CDF file with python on mac?

我已经使用以下命令安装了 spacepy (MacOS Mojave):

pip install git+https://github.com/spacepy/spacepy.git

但我在尝试 from spacepy import pycdf:

时不断收到此错误

Exception: Cannot load CDF C library; checked . Try 'os.environ["CDF_LIB"] = library_directory' before import.

我尝试遵循 the directions from their website,但这些说明似乎有点过时了。

您可以这样做:

import os
os.environ["CDF_LIB"] = "~/CDF/lib" # Give the path of the cdf library
# e.g. in this case the library is in your home directory.

做之前:

from spacepy import pycdf

错误来源可在 this SpacePy 网站上找到。

cdf 库可用 here

基本上,您需要在导入模块之前设置 CDF_LIB(如果 pycdf 找不到它)。您可以阅读文档 here.