Unexpected Token error - Rhino grasshopper and python

Hi,
I am beginner on python for grasshopper and have come across the following error when trying to use shrimpGIS :

  1. Solution exception:unexpected token ‘from’

ShrimpGIS: A basic plugin to read and write shapefile (GPL).

This file is part of ShrimpGIS.

Copyright (c) 2020, Antonello Di Nunzio antonellodinunzio@gmail.com.

You should have received a copy of the GNU General Public License

along with ShrimpGIS; If not, see http://www.gnu.org/licenses/.

@license GPL-3.0+ http://spdx.org/licenses/GPL-3.0+

“”"
Construct a ShrimpGIS Matrix to write Esri ASCII Raster format.
Args:
_values: Values to map into a rectangular ASCII matrix [list].
-
Values must be from left-right bottom-up.
How does result should looks like (left-right bottom-up)?

5 6 7 8 9
0 1 2 3 4
_num_x: Number of pixels at x [int].
_num_y: Number of pixels at y [int].

Returns:
    ASCII_matrix: ShrimpGIS Matrix.

“”"

ghenv.Component.Name = “ShrimpGIS Esri ASCII”
ghenv.Component.NickName = “shrimp_esri_ascii”
ghenv.Component.Message = “1.0.0”
ghenv.Component.Category = “ShrimpGIS”
ghenv.Component.SubCategory = “0 || Settings”
try: ghenv.Component.AdditionalHelpFromDocStrings = “1”
except: pass

import scriptcontext as sc
import os
import sys
##################ShrimpGIS#####################
try:
user_path = os.getenv(“APPDATA”)
sys.path.append(user_path)
from shrimp_gis import version
from shrimp_gis.geometry import Matrix

ghenv.Component.Message = __version__

except ImportError as e:
raise ImportError(“\nFailed to import ShrimpGIS: {0}\n\nCheck your ‘shrimp_gis’ folder in {1}”.format(e, os.getenv(“APPDATA”)))
################################################

def main():

if _values and _num_x and _num_y:
    matrix = Matrix(_values, _num_x, _num_y)
    
    return matrix
    
return None

ASCII_matrix = main()

I really would appreciate if someone can help me with this error.

Thanks,
Lisa

Hi Lisa. Other users have had the same issue with that plug in, if you scroll down and look at the first comment.

Edit: I installed LadyBug Tools 1.6 and reproduced the exact same error with ShrimpGIS 1.03 (Rhino 7 on Windows 10).

It’s a devious error. I still can’t find an uncommented from token in the ShrimpGIS code. I’ve no idea what LBT is doing to cause ShrimpGIS to misread its own code. But while ShrimpGIS is quite complicated, LBT is enormously complicated. Good luck to both teams solving this one!

Without Ladybug Tools, Version 1.03 seemed to work OK for me in Rhino 7, and I couldn’t find any errant “from” statements or syntax errors in the source code for 1.0, 1.01 or 1.02

Lisa, which version of Rhino and ShrimpGIS are you using? And have you also got ladybug tools installed, especially v1.5 or v1.6?

As Antonello is a lot more active on the LBT forum, I’ve cross-referenced this thread here: Shrimp GIS does not work with LBT anymore - ladybug-tools - Ladybug Tools | Forum
-w

Thanks Wim. I reckon I’ve got to the bottom of it, and have made a quick patched version to test this:

I think this is the issue:

numpy>=1.21.6
ShrimpGIS

Dependencies:

pyshp
utm
pygeoj

numpy==1.16.6

utm/utm at master · Turbo87/utm · GitHub conversion.py


try:
    #  UTM with Numpy installed, requiring numpy == 1.16.6
    # and Shrimp GIS with Ladybug Tools installed, which installs > 1.21.6

    import numpy as mathlib
    use_numpy = True
except ImportError:

    # Normal operation of the static copy of UTM shipped with ShrimpGIS without numpy
    import math as mathlib
    use_numpy = False
1 Like

So the easiest way to reproduce the error (1. Solution exception:unexpected token ‘from’), is to install LadyBug Tools, and in a GhPython component do:

import numpy

However I think I’ve fixed shrimpGIS’s dependency conflict. I don’t actually know how to use shrimpGIS or LadyBug Tools, but the no-numpy version above got rid of the “from” error myself and Lisa had, together with LadyBug Tools being installed.

If you don’t want to trust random code downloaded from the internet, it is very straightforward to simply edit file below in your existing shrimpGIS 1.03 zip file (shrimpGIS copies utm into %appdata%\shrimp_gis\utm so if you want to edit an already installed version it might need changing there as well as in UserObjects):

lib\shrimp_gis\utm\conversion.py

- try:
-    import numpy as mathlib
-    use_numpy = True
- except ImportError:
-    import math as mathlib
-    use_numpy = False

+ import math as mathlib
+ use_numpy = False