1

嗨,我是 python 和基于代理的建模的新手。

在运行可视化代码时,我正在关注mesa 高级教程并获得 NotImplementedError。

我之前遵循介绍性教程并成功创建了正常运行的 MoneyAgent 和 MoneyModel 类。

我在(高级教程)代码中复制如下:

from MoneyModel import *
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer


def agent_portrayal(agent):
    portrayal = {"Shape": "circle",
                 "Filled": "true",
                 "Layer": 0,
                 "Color": "red",
                 "r": 0.5}
    return portrayal

grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)
server = ModularServer(MoneyModel,
                       [grid],
                       "Money Model",
                       {"N":100, "width":10, "height":10})
server.port = 8521 # The default
server.launch()

但是得到一个“NotImplementedError”:

Traceback (most recent call last):
  File "C:/Users/antho/PycharmProjects/MesaSampleModel/Model/MoneyModel_Viz.py", line 20, in <module>
    server.launch()
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\mesa\visualization\ModularVisualization.py", line 321, in launch
    self.listen(self.port)
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Users\antho\PycharmProjects\MesaSampleModel\venv\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Users\antho\AppData\Local\Programs\Python\Python38-32\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError

任何人都可以帮忙吗?

4

1 回答 1

0

您需要在导入期间将这行代码添加到您的:

import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
于 2020-10-12T08:17:58.333 回答