Skip to content

Install

  • 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.
  1. 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).

  2. Search for Pywr and select the extension published by s-simoncelli.

  3. 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.

The extension runs your models with Python, so you need Python installed on your computer. Pywr v2 needs Python 3.10 or later. You can download it from python.org.

Pywr does not use the Python of your computer directly. It uses a Python environment: a folder, usually called .venv, with its own copy of Python and of the packages Pywr needs. Installing packages in it never changes the rest of your computer, and each project can have its own. A conda environment works too.

The extension can create the environment and install the packages for you.

  1. Open the folder with your model in VS Code (File > Open Folder…).

  2. Open the Command Palette with Ctrl Shift P (Cmd Shift P on macOS) and run Pywr: Set up the Python environment.

  3. Pick Pywr v2 or Pywr v1, the version your model is written for.

  4. Confirm the message that follows. If VS Code already uses an environment for this folder, the command installs the packages in it. Otherwise it creates a .venv folder in the folder you opened and tells VS Code to use it.

  5. Wait for the install to finish. It can take a few minutes the first time.

    When everything is in place, a message says the environment is ready. If a package could not be installed, an error names it. Press Show Output to read what went wrong.

If your model has Python parameters that import other packages, install those packages as in the last step of the manual setup.

If you prefer to manage the environment yourself, create it and install the packages from a terminal.

  1. Open the folder with your model in VS Code (File > Open Folder…).

  2. Open the Command Palette, run Python: Create Environment, choose Venv and pick a Python version. VS Code creates the environment in a .venv folder and selects it for the workspace.

    You can also create it from a terminal with python -m venv .venv.

  3. Check that the environment is selected: the status bar shows .venv next to the Python version. If it does not, run Python: Select Interpreter from the Command Palette and pick .venv.

  4. Open a new terminal (Terminal > New Terminal). VS Code activates the selected environment in it, so the prompt starts with (.venv). A terminal opened before you selected the environment is not activated: close it and open a new one.

    If the prompt does not show (.venv), activate it yourself:

    Terminal window
    .venv\Scripts\activate
  5. Install the packages for your version of Pywr in the activated terminal:

    Terminal window
    pip install pyarrow pandas polars tables

    Pywr v2 is built into the extension, so you do not install it. pyarrow, pandas and polars read the Pandas, Polars and Python timeseries. PyTables (tables) is used by the risk analysis and the QA report.

    Install any other package your Python parameters import in the same way.

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.

Pywr for VS Code and Pywr for Azure DevOps are developed and maintained by Stefano Simoncelli.