S
Solara9mo ago
Razzle

Running a file vs running a module

Hello! I am trying to get solara up and running for use with mesa but am having some issues. I structured my code as a python package and would like to be able to run solara run my-package (or even better, just my-package) in the cli to start the server. Currently, running solara run __main__.py works, but for some reason running solara run my-package does not. Adding a print statement to __main__.py, I can see it being printed but solara does not appear to be able to find the route:
Page not found by Solara router
Page not found by Solara router
My __main__.py looks like this:
from mesa.experimental import JupyterViz

print("Hello")

page = JupyterViz(
MyModel,
model_params,
measures=[],
name="Test Model",
agent_portrayal=agent_portrayal,
)
from mesa.experimental import JupyterViz

print("Hello")

page = JupyterViz(
MyModel,
model_params,
measures=[],
name="Test Model",
agent_portrayal=agent_portrayal,
)
Is there a way to just "run" the page, similar to Flask's app.run() and if not, how can I make the solara CLI tool pick up the page even when running the module instead of the __main__.py directly? Thanks
5 Replies
EdgeofChaos
EdgeofChaos9mo ago
@Razzle I work on mesa and you can runn and app form the command line using solara run <name>.py and exmaple is located in the mesa example repo boltzmann_wealth_experimental
GitHub
mesa-examples/examples/boltzmann_wealth_model_experimental at main ...
Seminal agent-based models developed using Mesa. Contribute to projectmesa/mesa-examples development by creating an account on GitHub.
Razzle
RazzleOP9mo ago
Thank you! I understand that, I am looking for how to integrate this "single-file" approach into a python pacakge, so that I don't have to ship the python file to the end user, and can just instruct them to run pip install mypackage, followied by solara run mypackage
MaartenBreddels
MaartenBreddels9mo ago
Did you try to put it in my-package/__init__.py ?
Razzle
RazzleOP9mo ago
Yes, I still get a Page not found by Solara router :(
MaartenBreddels
MaartenBreddels9mo ago
if solara run solara.website.pages runs, then you should check what the difference is. One thing I wonder about is if you also have a directory my-package? Although, that should give you the same result. Just as a sanity check, please define a Page component (since in the above i see a page element being used, which seems to be the only difference I think)
Want results from more Discord servers?
Add your server