OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
800 stars 293 forks source link

[Bug] g.gui.timeline fails with ctypes.OverflowError on Windows #2109

Open petrasovaa opened 2 years ago

petrasovaa commented 2 years ago

Describe the bug g.gui.timeline doesn't display anything, originally reported by @chaedri

To Reproduce t.create output=test semantictype=mean title=title description=desc t.register -i input=test maps=elev_lid792_1m@PERMANENT,elev_state_500m@PERMANENT start=2000-01-01 increment="1 month" g.gui.timeline test

Traceback (most recent call last):
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\cbook\__init__.py", line 287, in process
    func(*args, **kwargs)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\backend_bases.py", line 3061, in
mouse_move
    s = self._mouse_event_to_message(event)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\backend_bases.py", line 3041, in
_mouse_event_to_message
    s = event.inaxes.format_coord(event.xdata, event.ydata)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\axes\_base.py", line 4155, in
format_coord
    xs = self.format_xdata(x)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\axes\_base.py", line 4137, in
format_xdata
    return (self.fmt_xdata if self.fmt_xdata is not None
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\ticker.py", line 239, in
format_data_short
    return self.format_data(value)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\ticker.py", line 231, in format_data
    return self.__call__(value)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\dates.py", line 973, in __call__
    result = self._formatter(x, pos)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\dates.py", line 636, in __call__
    result = num2date(x, self.tz).strftime(self.fmt)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\dates.py", line 528, in num2date
    return _from_ordinalf_np_vectorized(x, tz).tolist()
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\numpy\lib\function_base.py", line 2113, in __call__
    return self._vectorize_call(func=func, args=vargs)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\numpy\lib\function_base.py", line 2197, in
_vectorize_call
    outputs = ufunc(*inputs)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\matplotlib\dates.py", line 357, in _from_ordinalf
    dt = dt.replace(tzinfo=dateutil.tz.gettz('UTC'))
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\tz.py", line 1557, in __call__
    rv = self.nocache(name=name)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\tz.py", line 1648, in nocache
    tz = tzwin(name)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\win.py", line 223, in __init__
    keydict = valuestodict(tzkey)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\win.py", line 366, in valuestodict
    value = tz_res.name_from_string(value)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\win.py", line 124, in name_from_string
    return self.load_name(offset)
  File "C:\Program Files\GRASS GIS 8.0\Python39\lib\site-
packages\dateutil\tz\win.py", line 93, in load_name
    nchar = self.LoadStringW(self._tzres._handle, offset,
lpBuffer, 0)
ctypes.ArgumentError: argument 1: <class 'OverflowError'>:
int too long to convert

Also can be simply reproduced with example from dateutil/tz/win.py tzres.load_name method:

from dateutil.tzwin import tzres
tzr = tzres()
tzr.load_name(112)

System description (please complete the following information):

Additional context This is not a problem of g.gui.timeline rather perhaps some packaging issue?

ecodiv commented 2 years ago

The same seems to be true for the temporal plot tool, g.gui.tplot doesn't display anything.

nilason commented 2 years ago

I wonder if not the patch to ctypesgen: https://github.com/OSGeo/grass/blob/c700a8a923cd8e7b0e49e5abab3a2ae313eccaef/python/libgrass_interface_generator/ctypesgen/libraryloader.py#L325-L329

which adds all PATH directories to dll loading, could cause this and other Windows issues like #2101 . I never felt good with that patch.

neteler commented 2 years ago

I never felt good with that patch.

What would to be changed to find out?

nilason commented 2 years ago

I never felt good with that patch.

What would to be changed to find out?

I'm not quite sure yet. I've been tinkering on a GRASS installation on a win can I have at my disposal, so far with no success.

neteler commented 2 years ago

Is this still an issue? Since the 8.0.2 milestone is due now - to which milestone may this report be bumped?

ecodiv commented 2 years ago

Is this still an issue?

As far as I can see, yes, it is. Same for the other gui's in the temporal toolbox.

Since the 8.0.2 milestone is due now - to which milestone may this report be bumped?

Not sure how difficult this is to fix, but it is one of those features that you want to work when introducing the grass temporal framework to (new) Window users. Just as a plea to not bump it up to far into the future ;-)

CDVS458 commented 1 year ago

Hey, I solved this problem on Windows by commenting line 59 (user32 = ctypes.WinDLL('user32')) in the file win.py and I changed the line by:

user32 = ctypes.WinDLL(r'C:\Windows\SysWOW64\user32')

I hope this help!

hellik commented 4 weeks ago

testing here with

System Info                                                                     
GRASS version: 8.3.2                                                            
Code revision: exported                                                         
Build date: 2024-05-20                                                          
Build platform: x86_64-w64-mingw32                                              
GDAL: 3.9.0                                                                     
PROJ: 9.4.0                                                                     
GEOS: 3.12.1                                                                    
SQLite: 3.45.1                                                                  
Python: 3.12.4                                                                  
wxPython: 4.2.1                                                                 
Platform: Windows-11-10.0.22631-SP0 (OSGeo4W)    

t.register -i input=test maps=basins@PERMANENT,landuse@PERMANENT start=2000-01-01 increment=1 month

g.gui.timeline test                                                             
Traceback (most recent call last):
  File
"C:\OSGeo4W\apps\grass\grass83/scripts/g.gui.timeline.py",
line 73, in <module>
    main()
  File
"C:\OSGeo4W\apps\grass\grass83/scripts/g.gui.timeline.py",
line 66, in main
    frame.SetDatasets(datasets)
  File "C:\OSGeo4W\apps\grass\grass83\gui\wxpython\timeline\
frame.py", line 576, in SetDatasets
    self._redraw()
  File "C:\OSGeo4W\apps\grass\grass83\gui\wxpython\timeline\
frame.py", line 462, in _redraw
    self._draw2dFigure()
  File "C:\OSGeo4W\apps\grass\grass83\gui\wxpython\timeline\
frame.py", line 393, in _draw2dFigure
    self.fig.autofmt_xdate()
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\figure.py", line 264, in autofmt_xdate
    for label in self.axes[0].get_xticklabels(which=which):
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\axes\_base.py", line 73, in wrapper
    return get_method(self)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\axis.py", line 1460, in get_ticklabels
    return self.get_majorticklabels()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\axis.py", line 1424, in
get_majorticklabels
    self._update_ticks()
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\axis.py", line 1275, in _update_ticks
    major_locs = self.get_majorticklocs()
                 ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\axis.py", line 1495, in
get_majorticklocs
    return self.major.locator()
           ^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\dates.py", line 1373, in __call__
    dmin, dmax = self.viewlim_to_dt()
                 ^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\dates.py", line 1158, in viewlim_to_dt
    return num2date(vmin, self.tz), num2date(vmax, self.tz)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\dates.py", line 543, in num2date
    return _from_ordinalf_np_vectorized(x, tz).tolist()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\numpy\lib\function_base.py", line 2372, in __call__
    return self._call_as_normal(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\numpy\lib\function_base.py", line 2365, in
_call_as_normal
    return self._vectorize_call(func=func, args=vargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\numpy\lib\function_base.py", line 2455, in
_vectorize_call
    outputs = ufunc(*inputs)
              ^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\matplotlib\dates.py", line 369, in _from_ordinalf
    dt = dt.replace(tzinfo=dateutil.tz.gettz('UTC'))
                           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\tz.py", line 1557, in __call__
    rv = self.nocache(name=name)
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\tz.py", line 1648, in nocache
    tz = tzwin(name)
         ^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\win.py", line 221, in __init__
    keydict = valuestodict(tzkey)
              ^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\win.py", line 364, in valuestodict
    value = tz_res.name_from_string(value)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\win.py", line 122, in name_from_string
    return self.load_name(offset)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\OSGeo4W\apps\Python312\Lib\site-
packages\dateutil\tz\win.py", line 91, in load_name
    nchar = self.LoadStringW(self._tzres._handle, offset,
lpBuffer, 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ctypes.ArgumentError: argument 1: OverflowError: int too
long to convert

still failing

hellik commented 4 weeks ago

random internet search

ctypes silently truncates ints larger than C int: A Python int larger than a C int but smaller than a C long is silently truncated to int when passed to a ctypes function without C type information attached.

hellik commented 4 weeks ago

Hey, I solved this problem on Windows by commenting line 59 (user32 = ctypes.WinDLL('user32')) in the file win.py and I changed the line by:

user32 = ctypes.WinDLL(r'C:\Windows\SysWOW64\user32')

I hope this help!

changing this line in C:\OSGeo4W\apps\Python312\Lib\site-packages\dateutil\tz\win.py

grafik

g.gui.timeline works.

anyone any idea to solve?

neteler commented 4 weeks ago

changing this line in C:\OSGeo4W\apps\Python312\Lib\site-packages\dateutil\tz\win.py

So that would be here in the upstream `dateutil'package:

https://github.com/dateutil/dateutil/blob/0353b78b2d620816e8c37fa9025fc3862671303a/src/dateutil/tz/win.py#L59