mesa-geo icon indicating copy to clipboard operation
mesa-geo copied to clipboard

Error in extracting agent from GeoSpace.agents in tutorial using Spyder

Open whitbern opened this issue 11 months ago • 6 comments

this is an attachment of the script mesa_geo_tutorial.txt this is a screenshot of the error error_mesa_geo_tutorial

Good evening, currently, I am doing the tutorial for Mesa-geo using Spyder. When I try to extract the agents using this line:

agent = m.space.agents[0]

I get a TypeError stating that: 'type' object is not subscriptable. Before that, I get a "Coordinate = tuple[int, int]." However, when I look at the mesa.space module, they mention lists?

I would expect for this just to give me the first agent from the listed url.

Thankfully this works just fine in Jupyter Notebook. Can you all help me figure out why this is not working in Spyder? Thanks!

whitbern avatar Mar 14 '24 04:03 whitbern

Thanks for sharing the code and screenshot. The error appears to be from type hints. Can I ask which version of Python you were using?

Mesa & Mesa-Geo require Python 3.9 and above. I couldn't reproduce the error with Python 3.10. Perhaps try to recreate a clean virtual environment with Python 3.9 or above, install Mesa-Geo and try again?

wang-boyu avatar Mar 21 '24 16:03 wang-boyu

This is indeed an error caused by new syntax introduced in Python 3.9. Upgrading should resolve the problem.

@wang-boyu the more interesting problem is how users manage to install Mesa-geo with incompatible Python versions. Have we set our Python requirements correctly in this repo? https://packaging.python.org/en/latest/guides/dropping-older-python-versions/#specify-the-version-ranges-for-supported-python-distributions

EwoutH avatar Mar 21 '24 17:03 EwoutH

Python requirement is specified in the setup.cfg file: https://github.com/projectmesa/mesa-geo/blob/b717971075a99ed18cd06126183c75407baa8dcb/setup.cfg#L29 I suppose it should work as expected...?

Edit: in python 3.8 I could only install mesa-geo 0.8.0. When attempting to install 0.9.0, there is an error message indicating python >= 3.9 is required, which is as expected.

wang-boyu avatar Mar 21 '24 17:03 wang-boyu

Yes, this is indeed the case and it's configured correctly: https://github.com/EwoutH/mesa/actions/runs/8379466683

@whitbern which version of mesa-geo are you using and which Python version? How did you install mesa-geo?

EwoutH avatar Mar 21 '24 17:03 EwoutH

Hello--I have Python 3.11.5 I have the latest version of mesa-geo: 0.7.0. I installed mesa-geo using these commands for Windows in the Anaconda Prompt:

conda install fiona pyproj rtree shapely pip install mesa-geo

whitbern avatar Mar 21 '24 18:03 whitbern

Right, I read the error wrongly. Seems like an issue in the GeoSpace or the mesa space itself.

  1. Which mesa version are you using?
  2. Could you print m.space.agents and its type.
  3. Could you update to the latest versions of both mesa and mesa-geo and see if this error still persists?

EwoutH avatar Mar 21 '24 19:03 EwoutH