我有一个 Colab 项目,它使用
h3pandas
进行填充,但导入 h3pandas
会引发 ImportError。
添加这些库后:
!pip install h3pandas
import pandas as pd
import matplotlib.pyplot as plt
import h3pandas
我收到此错误:
ImportError Traceback (most recent call last)
<ipython-input-2-5e53e9308d98> in <cell line: 3>()
1 import pandas as pd
2 import matplotlib.pyplot as plt
----> 3 import h3pandas
1 frames
/usr/local/lib/python3.10/dist-packages/h3pandas/h3pandas.py in <module>
9 import geopandas as gpd
10
---> 11 from h3 import h3
12 from pandas.core.frame import DataFrame
13 from geopandas.geodataframe import GeoDataFrame`
ImportError: cannot import name 'h3' from 'h3' (/usr/local/lib/python3.10/dist-packages/h3/__init__.py)
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
这是 H3-Pandas 中的一个已知错误。从 h3-py v4.0.0 开始,名称
h3.h3
不再存在,因此 H3-Pandas 源代码中的行 from h3 import h3
会抛出 ImportError。
作为解决方法,您可以手动安装仍包含该名称的 H3 版本。任何 v3 版本都可以工作 - 在撰写本文时,最新版本是 v3.7.7,但您也可以只是
pip install h3~=3.0
。
!pip install h3pandas
!pip install h3~=3.0
import pandas as pd
import matplotlib.pyplot as plt
import h3pandas