SMoG-Chalmers / PST

PST is a tool for performing space syntax and regular accessibility analyses. It currently consists of two main parts - a C++ and Python library called Pstalgo and a plugin for the desktop application QGIS
GNU Lesser General Public License v3.0
43 stars 7 forks source link

Error loading plugin - UnicodeDecodeError: 'ascii' codec can't decode byte #2

Closed e-kotov closed 3 years ago

e-kotov commented 3 years ago

Unable to load the plugin in the latest QGIS LTR 3.16.5 and QGIS 3.18.1, at least on macOS Big Suer 11.2.3 (20D91). The plugin is correctly extracted to ~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/pst , however when launching QGIS I get the following error. I do not know if there is a similar problem on Windows or Linux.

Below is the error message of QGIS:

Couldn't load plugin 'pst' 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 109: ordinal not in range(128) 
Traceback (most recent call last):
  File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 312, in loadPlugin
    __import__(packageName)
  File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "/Users/ek/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/pst/__init__.py", line 36, in 
    APP_TITLE = MetaData()['general']['name']
  File "/Users/ek/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/pst/__init__.py", line 33, in MetaData
    metadata.read(metadata_path)
  File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/configparser.py", line 697, in read
    self._read(fp, filename)
  File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/configparser.py", line 1017, in _read
    for lineno, line in enumerate(fp, start=1):
  File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 109: ordinal not in range(128)

Python version: 3.8.7 (default, Feb 10 2021, 09:04:08) [Clang 12.0.0 (clang-1200.0.32.29)] 
QGIS version: 3.16.5-Hannover Hannover, 58ba7c1ed6 

Python Path:
/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python
~/Library/Application Support/QGIS/QGIS3/profiles/default/python
~/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/plugins
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/affine-2.3.0-py3.8.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pandas-1.1.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python38.zip
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/snuggs-1.4.7-py3.8.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/patsy-0.5.1-py3.8.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Rtree-0.9.4-py3.8.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/netCDF4-1.5.4-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/opencv_contrib_python-4.3.0.36-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Pillow-7.2.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/numpy-1.20.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/statsmodels-0.11.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/GDAL-3.2.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/lib-dynload
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/cftime-1.2.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/scipy-1.5.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/numba-0.50.1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pyproj-2.6.0-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/click_plugins-1.1.1-py3.8.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Fiona-1.8.13.post1-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/rasterio-1.1.5-py3.8-macosx-10.13.0-x86_64.egg
/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/geopandas-0.8.1-py3.8.egg

After that the plugin does not appear in the menus and therefore cannot be accessed. The problem is with the non-ascii characters in the metadata.txt, specifically with the plugin authors' names. If I remove the names, or at least the names with non-ascii characters from the metadata.txt, the plugin loads and works normally. But of course there is a better solution, I will submit a pull request with a quick fix shortly.

jack89roberts commented 3 years ago

Just a note to say I was having the same problem on macOS Catalina (10.15.7) and PR #3 fixed it for me - thanks @e-kotov !

e-kotov commented 3 years ago

Resolved with https://github.com/SMoG-Chalmers/PST/commit/e4f806dde9b9e6f22d90927713349defa51f0cb8#diff-a2fac7c9c45eab214aefd09b8c23ad0ce0b67a20657608daac414222964a3575 in latest https://github.com/SMoG-Chalmers/PST/releases/tag/v3.2.2 release