【问题标题】:Module 'geopandas' has no attribute 'read_file'模块“geopandas”没有属性“read_file”
【发布时间】:2018-01-03 09:04:22
【问题描述】:

我正在尝试像这样在 geopandas 中打开一个形状文件:

import geopandas as gpd

shp = gpd.read_file("C:\my_file.shp")

但这会返回错误:

Traceback (most recent call last):

  File "<ipython-input-5-d0665b3cc874>", line 3, in <module>
    shp = gpd.read_file("C:\my_file.shp")

AttributeError: module 'geopandas' has no attribute 'read_file'

我也尝试过这样做:

from geopandas import GeoSeries, GeoDataFrame

返回:

Traceback (most recent call last):

  File "<ipython-input-6-338cbf14bf64>", line 1, in <module>
    from geopandas import GeoSeries, GeoDataFrame

  File "C:\Users\spotter\Documents\Python_Scripts\geopandas.py", line 1, in <module>
    from geopandas import GeoSeries, GeoDataFrame

ImportError: cannot import name 'GeoSeries'

我正在使用 anaconda3-5.0.1 并使用 conda install -c conda-forge geopandas 安装 geopandas

编辑:

我刚刚下载了anaconda2,geopandas工作正常,所以这与anaconda3有关

【问题讨论】:

  • 你有一个名为geopandas.py的本地模块吗?

标签: python geopandas


【解决方案1】:

您不应将文件名命名为 geopandas.py。从from geopandas import GeoSeries, GeoDataFrame 的回溯中,我们可以知道您使用的文件名是geopandas.py,它使Python 导入该文件而不是geopandas 模块。将此文件在以下路径更改为其他名称,它应该可以工作。

from geopandas import GeoSeries, GeoDataFrame

File "C:\Users\XXXXX\Documents\Python_Scripts\geopandas.py", line 1, in <module>

                                            ---------------

【讨论】:

    猜你喜欢
    • 2021-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 2021-12-24
    • 2015-05-08
    • 2020-10-17
    • 2020-10-03
    相关资源
    最近更新 更多