0

I'm working with ArGIS Desktop 10.5 and python 2.7, and just installed geopandas to try it out. However, when I tried to read a shapefile, I received an encoding error:

import arcpy
import geopandas as gpd

data = gpd.read_file(r"<file_path_here>.shp", encoding='utf-8')

I know the shapefile has special characters (portuguese text), but I don't understand why the UTF-8 encoding is not working. I have never changed any default encoding properties. How could I fix this problem? Is there a way to check the shapefile's encoding?

Edit: sorry, I forgot the error message

File "<stdin>", line 1, in <module>
  File "C:\Python27\ArcGIS10.5\lib\site-packages\geopandas\io\file.py", line 76, in read_file
    with reader(path_or_bytes, **kwargs) as features:
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\env.py", line 398, in wrapper
    return f(*args, **kwargs)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\__init__.py", line 257, in open
    layer=layer, enabled_drivers=enabled_drivers, **kwargs)
  File "C:\Python27\ArcGIS10.5\lib\site-packages\fiona\collection.py", line 154, in __init__
    self.session.start(self, **kwargs)
  File "fiona\ogrext.pyx", line 466, in fiona.ogrext.Session.start
UnicodeDecodeError: 'ascii' codec can't decode byte 0x87 in position 34: ordinal not in range(128)

These are the packages' versions I was able to install (using wheels from lfd.uci.edu/~gohlke/pythonlibs/#fiona)

  • GDAL-2.2.4-cp27-cp27m-win32.whl
  • pyproj-1.9.6-cp27-cp27m-win32.whl
  • Fiona-1.8.13-cp27-cp27m-win32.whl
  • Shapely-1.6.4.post2-cp27-cp27m-win32.whl
  • geopandas-0.6.2-py2.py3-none-any.whl

For some reason, python 2.7 won't upgrade/ accept geopandas for version 10...

18
  • 1
    Python 2.7 ? Is it still alive ? Ooo … I forgot it is ESRI. Can you read the shape file with Portuguese encoding?
    – Taras
    Commented May 12, 2022 at 20:27
  • gis.stackexchange.com/a/339883/99589
    – Taras
    Commented May 12, 2022 at 20:57
  • I can't... I have tried these: utf-8, latin-1, ISO 8859-1 None worked. I don't know how ArcGIS is encoding this shapefile. Commented May 13, 2022 at 10:26
  • Can you share your data here?
    – Taras
    Commented May 13, 2022 at 10:26
  • 1
    I tried upgrading, but it didn't work. I think recent versions of geopandas won't work with Python 2.7... Commented May 13, 2022 at 10:54

0