模块'geopandas'没有属性'read_file'

问题描述 投票:0回答:1

我正试图在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有关

python geopandas
1个回答
2
投票

您不应将文件名命名为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>

                                            ---------------
© www.soinside.com 2019 - 2024. All rights reserved.