Getting TypeError: argument of type 'CRS' is not iterable with OSMnx Package

Getting TypeError: argument of type 'CRS' is not iterable with OSMnx Package

这道题, but none of the answers helped in my case. First I should say that I've followed the OSMnx Installation步骤完全正确。然后尝试在 Jupyter Notebook 中 运行 以下代码:

place = "San Francisco, California, USA"
g = ox.graph_from_place(place, network_type="bike")

尝试这个简单的代码后,返回了以下错误消息:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-d7dc3d6ea906> in <module>()
      1 #Get Bay Area Bike Network
      2 place = "San Francisco, California, USA"
----> 3 g = ox.graph_from_place(place, network_type="bike")

/Users/jcroff/anaconda3/envs/ox/lib/python3.6/site-packages/osmnx/core.py in graph_from_place(query, network_type, simplify, retain_all, truncate_by_edge, name, which_result, buffer_dist, timeout, memory, max_query_area_size, clean_periphery, infrastructure)
   1809                            name=name, timeout=timeout, memory=memory,
   1810                            max_query_area_size=max_query_area_size,
-> 1811                            clean_periphery=clean_periphery, infrastructure=infrastructure)
   1812 
   1813     log('graph_from_place() returning graph with {:,} nodes and {:,} edges'.format(len(list(G.nodes())), len(list(G.edges()))))

/Users/jcroff/anaconda3/envs/ox/lib/python3.6/site-packages/osmnx/core.py in graph_from_polygon(polygon, network_type, simplify, retain_all, truncate_by_edge, name, timeout, memory, max_query_area_size, clean_periphery, infrastructure)
   1678         # create a new buffered polygon 0.5km around the desired one
   1679         buffer_dist = 500
-> 1680         polygon_utm, crs_utm = project_geometry(geometry=polygon)
   1681         polygon_proj_buff = polygon_utm.buffer(buffer_dist)
   1682         polygon_buffered, _ = project_geometry(geometry=polygon_proj_buff, crs=crs_utm, to_latlong=True)

/Users/jcroff/anaconda3/envs/ox/lib/python3.6/site-packages/osmnx/projection.py in project_geometry(geometry, crs, to_crs, to_latlong)
     51     gdf['geometry'] = None
     52     gdf.loc[0, 'geometry'] = geometry
---> 53     gdf_proj = project_gdf(gdf, to_crs=to_crs, to_latlong=to_latlong)
     54     geometry_proj = gdf_proj['geometry'].iloc[0]
     55     return geometry_proj, gdf_proj.crs

/Users/jcroff/anaconda3/envs/ox/lib/python3.6/site-packages/osmnx/projection.py in project_gdf(gdf, to_crs, to_latlong)
    100             # else, project the gdf to UTM
    101             # if GeoDataFrame is already in UTM, just return it
--> 102             if (gdf.crs is not None) and ('proj' in gdf.crs) and (gdf.crs['proj'] == 'utm'):
    103                 return gdf
    104 

TypeError: argument of type 'CRS' is not iterable

供参考,以下是我的conda环境的包:

# packages in environment at /Users/jcroff/anaconda3/envs/ox:
#
# Name                    Version                   Build  Channel
appnope                   0.1.2            py36h79c6626_1    conda-forge
argon2-cffi               20.1.0           py36h20b66c6_2    conda-forge
async_generator           1.10                       py_0    conda-forge
attrs                     21.2.0             pyhd8ed1ab_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bleach                    3.3.0              pyh44b312d_0    conda-forge
boost-cpp                 1.74.0               h43a636a_2    conda-forge
branca                    0.4.2              pyhd8ed1ab_0    conda-forge
brotlipy                  0.7.0           py36h20b66c6_1001    conda-forge
bzip2                     1.0.8                h0d85af4_4    conda-forge
c-ares                    1.17.1               h0d85af4_1    conda-forge
ca-certificates           2020.12.5            h033912b_0    conda-forge
cairo                     1.16.0            he43a7df_1008    conda-forge
certifi                   2020.12.5        py36h79c6626_1    conda-forge
cffi                      1.14.5           py36hfaecaff_0    conda-forge
cfitsio                   3.470                h01dc385_7    conda-forge
chardet                   4.0.0            py36h79c6626_1    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
click-plugins             1.1.1                      py_0    conda-forge
cligj                     0.7.1              pyhd8ed1ab_0    conda-forge
cryptography              3.4.7            py36h3d45be8_0    conda-forge
curl                      7.76.1               h06286d4_1    conda-forge
cycler                    0.10.0                     py_2    conda-forge
decorator                 5.0.7              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
descartes                 1.1.0                      py_4    conda-forge
entrypoints               0.3             pyhd8ed1ab_1003    conda-forge
expat                     2.3.0                he49afe7_0    conda-forge
fiona                     1.8.19           py36hba155ba_0    conda-forge
folium                    0.12.0             pyhd8ed1ab_1    conda-forge
fontconfig                2.13.1            h10f422b_1005    conda-forge
freetype                  2.10.4               h4cff582_1    conda-forge
freexl                    1.0.6                h0d85af4_0    conda-forge
gdal                      3.2.2            py36h99bc8e5_3    conda-forge
geographiclib             1.50                       py_0    conda-forge
geopandas                 0.9.0              pyhd8ed1ab_0    conda-forge
geopy                     2.1.0              pyhd3deb0d_0    conda-forge
geos                      3.9.1                he49afe7_2    conda-forge
geotiff                   1.6.0                hba2ba3e_5    conda-forge
gettext                   0.19.8.1          h7937167_1005    conda-forge
giflib                    5.2.1                hbcb3906_2    conda-forge
hdf4                      4.2.13            hefd3b78_1005    conda-forge
hdf5                      1.10.6          nompi_hc5d9132_1114    conda-forge
icu                       68.1                 h74dc148_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
importlib-metadata        4.0.1            py36h79c6626_0    conda-forge
ipykernel                 5.5.4            py36h495a4c6_0    conda-forge
ipython                   5.8.0                    py36_1    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jinja2                    2.11.3             pyh44b312d_0    conda-forge
jpeg                      9d                   hbcb3906_0    conda-forge
json-c                    0.15                 hcb556a6_0    conda-forge
jsonschema                3.2.0              pyhd8ed1ab_3    conda-forge
jupyter_client            6.1.12             pyhd8ed1ab_0    conda-forge
jupyter_core              4.7.1            py36h79c6626_0    conda-forge
jupyterlab_pygments       0.1.2              pyh9f0ad1d_0    conda-forge
kealib                    1.4.14               h31dd65d_2    conda-forge
kiwisolver                1.3.1            py36h615c93b_1    conda-forge
krb5                      1.17.2               h60d9502_0    conda-forge
libblas                   3.9.0                9_openblas    conda-forge
libcblas                  3.9.0                9_openblas    conda-forge
libcurl                   7.76.1               h8ef9fac_1    conda-forge
libcxx                    11.1.0               habf9029_0    conda-forge
libdap4                   3.20.6               h3e144a0_2    conda-forge
libedit                   3.1.20191231         h0678c8f_2    conda-forge
libev                     4.33                 haf1e3a3_1    conda-forge
libffi                    3.3                  h046ec9c_2    conda-forge
libgdal                   3.2.2                h9a52621_3    conda-forge
libgfortran               5.0.0           9_3_0_h6c81a4c_22    conda-forge
libgfortran5              9.3.0               h6c81a4c_22    conda-forge
libglib                   2.68.2               hd556434_0    conda-forge
libiconv                  1.16                 haf1e3a3_0    conda-forge
libkml                    1.3.0             h8fd9edb_1013    conda-forge
liblapack                 3.9.0                9_openblas    conda-forge
libnetcdf                 4.8.0           nompi_h81fa352_101    conda-forge
libnghttp2                1.43.0               h07e645a_0    conda-forge
libopenblas               0.3.15          openmp_h5e1b9a4_0    conda-forge
libpng                    1.6.37               h7cec526_2    conda-forge
libpq                     13.2                 h052a64a_2    conda-forge
librttopo                 1.1.0                h5413771_6    conda-forge
libsodium                 1.0.18               hbcb3906_1    conda-forge
libspatialindex           1.9.3                h1c7c35f_3    conda-forge
libspatialite             5.0.1                heb715ac_4    conda-forge
libssh2                   1.9.0                h52ee1ee_6    conda-forge
libtiff                   4.2.0                h7c11950_1    conda-forge
libwebp-base              1.2.0                h0d85af4_2    conda-forge
libxml2                   2.9.10               h93ec3fd_4    conda-forge
libzip                    1.7.3                hbc046b2_0    conda-forge
llvm-openmp               11.1.0               hda6cdc1_1    conda-forge
lz4-c                     1.9.3                h046ec9c_0    conda-forge
markupsafe                1.1.1            py36h20b66c6_3    conda-forge
matplotlib                3.2.2                         1    conda-forge
matplotlib-base           3.2.2            py36h83d3ec1_1    conda-forge
mistune                   0.8.4           py36h20b66c6_1003    conda-forge
munch                     2.5.0                      py_0    conda-forge
nbclient                  0.5.3              pyhd8ed1ab_0    conda-forge
nbconvert                 6.0.7            py36h79c6626_3    conda-forge
nbformat                  5.1.3              pyhd8ed1ab_0    conda-forge
ncurses                   6.2                  h2e338ed_4    conda-forge
nest-asyncio              1.5.1              pyhd8ed1ab_0    conda-forge
networkx                  2.3                        py_0    conda-forge
notebook                  6.3.0            py36h79c6626_0    conda-forge
numpy                     1.19.5           py36h08dc641_1    conda-forge
openjpeg                  2.4.0                h6cbf5cd_0    conda-forge
openssl                   1.1.1k               h0d85af4_0    conda-forge
osmnx                     0.7.3                    py36_0    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
pandas                    1.1.5            py36h2be6da3_0    conda-forge
pandoc                    2.13                 h0d85af4_0    conda-forge
pandocfilters             1.4.2                      py_1    conda-forge
pcre                      8.44                 hb1e8313_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       21.1.1             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               hbcb3906_0    conda-forge
poppler                   21.03.0              h640f9a4_0    conda-forge
poppler-data              0.4.10                        0    conda-forge
postgresql                13.2                 ha63e576_2    conda-forge
proj                      8.0.0                h1512c50_0    conda-forge
prometheus_client         0.10.1             pyhd8ed1ab_0    conda-forge
prompt_toolkit            1.0.15                     py_1    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.9.0              pyhd8ed1ab_0    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pyproj                    3.0.1            py36hc662631_1    conda-forge
pyrsistent                0.17.3           py36h20b66c6_2    conda-forge
pysocks                   1.7.1            py36h79c6626_3    conda-forge
python                    3.6.13          h7728216_0_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.6                     1_cp36m    conda-forge
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pyzmq                     22.0.3           py36h50cd92c_1    conda-forge
readline                  8.1                  h05e3726_0    conda-forge
requests                  2.25.1             pyhd3deb0d_0    conda-forge
rtree                     0.9.7            py36h49c2f37_1    conda-forge
send2trash                1.5.0                      py_0    conda-forge
setuptools                49.6.0           py36h79c6626_3    conda-forge
shapely                   1.7.1            py36h7f0d9e5_4    conda-forge
simplegeneric             0.8.1                      py_1    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
sqlite                    3.35.5               h44b9ce1_0    conda-forge
terminado                 0.9.4            py36h79c6626_0    conda-forge
testpath                  0.4.4                      py_0    conda-forge
tiledb                    2.2.9                he9a4fb4_0    conda-forge
tk                        8.6.10               h0419947_1    conda-forge
tornado                   6.1              py36h20b66c6_1    conda-forge
traitlets                 4.3.3            py36h9f0ad1d_1    conda-forge
typing_extensions         3.7.4.3                    py_0    conda-forge
tzcode                    2021a                h0d85af4_1    conda-forge
tzdata                    2021a                he74cb21_0    conda-forge
urllib3                   1.26.4             pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
xerces-c                  3.2.3                h379762d_2    conda-forge
xz                        5.2.5                haf1e3a3_1    conda-forge
zeromq                    4.3.4                h1c7c35f_0    conda-forge
zipp                      3.4.1              pyhd8ed1ab_0    conda-forge
zlib                      1.2.11            h7795811_1010    conda-forge
zstd                      1.4.9                h582d3a0_0    conda-forge

在查看上述问题的答案时,开发人员似乎不支持恢复到旧版本的 geopandas,因为过去的几个版本需要 geopandas>=0.7。非常感谢解决此问题的任何帮助!谢谢。

您安装的 OSMnx 版本太旧。您的 conda list 输出显示您安装了 0.7.3 版本,该版本是 3 或 4 年前发布的。它太旧了,与 GeoPandas 和 pyproj 的现代功能不兼容,包括导致错误的现代 CRS 对象。我不清楚你是怎么做到的!我最好的猜测是您使用此 page 上的旧标签之一进行安装,它确实指向版本 0.7.3。

这应该通过删除旧环境然后按照安装说明 here 来解决,例如:

conda env remove -n ox
conda clean --all --yes
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx