Install
What you need
Section titled “What you need”- Visual Studio Code 1.110 or later. Check your version with Help > About (Code > About Visual Studio Code on macOS). You download it from the official VSCode website.
- A Python environment, only to run models. You can explore, edit, draw and validate a model, and chart existing results, without Python.
Install the extension
Section titled “Install the extension”-
Open VS Code and open the Extensions view, with the icon in the activity bar or with Ctrl Shift X (Cmd Shift X on macOS).
-
Search for Pywr and select the extension published by s-simoncelli.
-
Press Install.
The Python extension is installed with it, because it is used to select the Python environment.
You can also install it from its page on the Visual Studio Marketplace.
The extension starts when you open a JSON file. When the file is a Pywr model, the Pywr icon in the activity bar opens the sidebar with the components of the model.
Set up Python to run models
Section titled “Set up Python to run models”To run a model, the extension needs a Python environment: a virtual environment or a conda environment. A system-wide Python is refused, so that running a model never depends on, or changes, the Python of your machine.
Pywr v2 is built into the extension, so you do not install it. The environment is used to process the Python parameters of your model and to read timeseries with pandas, polars or your own Python function.
- Python 3.10 or later.
- Install
pyarrowin the environment if your model has Pandas, Polars or Python timeseries, pluspandasorpolarsfor the first two. - Install any package your own Python parameters import.
Pywr v1 models are run by pywr itself, from your environment.
- Install pywr 1 in the environment with
pip install pywr.
-
Open the folder with your model in VS Code (File > Open Folder…).
-
Open a terminal in VS Code (Terminal > New Terminal) and create an environment in that folder:
Terminal window python -m venv .venv -
For a Pywr v1 model, activate the environment and install pywr:
Terminal window .venv\Scripts\activatepip install pywrTerminal window source .venv/bin/activatepip install pywr -
Open the Command Palette with Ctrl Shift P (Cmd Shift P on macOS), run Python: Select Interpreter and pick the environment you created (
.venv).
If a run fails with a message about the Python environment, see Troubleshooting.
Follow Your first model to create, run and chart a model, or open a model you already have and read Explore the model.