enzet / map-machine

Python renderer for OpenStreetMap with custom icons intended to display as many map features as possible
MIT License
515 stars 34 forks source link

ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory #153

Closed CoderThomasB closed 1 year ago

CoderThomasB commented 1 year ago

I'm new to this project and I have just installed it using pip, but when I try to run the map-machine command both with and without options it crashes with this python error:

Traceback (most recent call last):
  File "/home/thomas/.local/bin/map-machine", line 5, in <module>
    from map_machine.main import main
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/main.py", line 21, in <module>
    from map_machine.ui.cli import parse_arguments
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/ui/cli.py", line 5, in <module>
    from map_machine.map_configuration import BuildingMode, DrawingMode, LabelMode
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/map_configuration.py", line 9, in <module>
    from map_machine.pictogram.icon import ShapeExtractor, IconSet
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/pictogram/icon.py", line 367, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1223, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1213, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory

The expected behaviour is of course that it doesn't crash.

I'm using python 3.11 which is much higher than 3.9 which is the suggested version but when I run it with 3.9 it says that ModuleNotFoundError: No module named 'map_machine'

I'm also using the fedora distribution of Linux.

If there is anything else that I have left out of this bug report, then I would be happy to add it in a comment.

FabienSailliet commented 1 year ago

I have the same issue. I would have loved to try this program that looks like exactly what I need, but this issue prevents me to do so. It looks like it has been fixed in the pending merge request, will it be released soon?

enzet commented 1 year ago

I've merged the request by @phillies.

Please, reopen the issue if the problem still persists.

CoderThomasB commented 1 year ago

I've just pulled the latest changes from the git repo which includes the fix and the issue is persisting with what looks to be the same back trace.

Traceback (most recent call last):
  File "/home/thomas/Projects/map-machine/map_machine/__main__.py", line 2, in <module>
    from map_machine.main import main
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/main.py", line 21, in <module>
    from map_machine.ui.cli import parse_arguments
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/ui/cli.py", line 5, in <module>
    from map_machine.map_configuration import BuildingMode, DrawingMode, LabelMode
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/map_configuration.py", line 9, in <module>
    from map_machine.pictogram.icon import ShapeExtractor, IconSet
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/pictogram/icon.py", line 367, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1223, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1213, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory
enzet commented 1 year ago

Hi, @CoderThomasB, thank you for the quick feedback!

There may have been a problem with the update because I haven't updated the minor version. I'll fix it. If the problem persists after that, could you please specify the command you are using so that I can try to reproduce it?

CoderThomasB commented 1 year ago

@enzet Oops, I thought I was running the new version's main.py file from the git repo, but on a closer look it's actually just importing other stuff from the old pip version.

Fetching and installing the new version, using pip install git+https://github.com/enzet/map-machine, works. So this issue is solved for me at least!

Thanks for responding to my message quickly and merging the patch. I'm having a fun time playing around with your amazing map renderer, now that it's working!

enzet commented 1 year ago

@CoderThomasB I believe version bumping was needed for pip install --upgrade to work correctly.

Thank you, hope the project is useful for you!