Landlab developer install on Windows (with Visual Studio)

Note: If you don’t use Visual Studio (e.g., on other C/C++ projects), a simpler (and preferred) method for setting up Landlab can be found at Landlab developer install on Windows (with gcc).


Building Landlab from source on Windows is trickier than on Linux or macOS. Below are some steps, based on recent experience, that should work.

Install Visual Studio

Landlab has many parts that are written in C, and we need a C compiler to build them. Download Visual Studio Community Edition and install it. We don’t need to use Visual Studio directly, but the compiler and linker included with it are used in the Landlab build process.

During installation, be sure to select this option:

  • “Desktop development with C++” workload

This is what will install the compiler and linker with Visual Studio.

Install Miniforge

To set up a Python environment to run Landlab, we use Miniforge. Download the Windows installer for Miniforge and run it.

During installation, be sure to select these three options:

  • “Create shortcuts”
  • “Add Miniforge3 to my PATH environment variable” (even though a warning is given against this)
  • “Register Miniforge as my default Python”

We’ll use the Miniforge Prompt, which is installed in the Windows Start menu, for the next steps.

Create a conda environment

Through the Miniforge prompt, use conda to create a virtual environment for the Landlab developer install.

conda create -y -n landlab_dev python pip compilers git

Note that we’re including the conda compilers (which map to Visual Studio) in this environment, as well as git, pip, and python, all of which we’ll use below.

Activate the new environment.

conda activate landlab_dev

A host of status messages will stream past. The messages should end with text like this:

[vcvarsall.bat] Environment initialized for: 'x64'

Clone the Landlab repository

From the Miniforge prompt, use git to clone the Landlab repository to your computer.

git clone git@github.com:landlab/landlab.git

You may wish to fork Landlab and clone your fork instead. You’ll need an SSH key pair set up on your computer for communicating with GitHub. See this lesson from CSDMS Ivy for more information.

The cloned repository lives in a directory called landlab. Change to this directory.

cd landlab

Install Landlab into the conda environment

From the Miniforge prompt, in the landlab directory with the activated landlab_dev environment, build Landlab from source and install it with pip.

pip install -e ".[dev,testing]"

Check that Landlab is installed by starting a Python session from the Miniforge prompt.

python

In the Python session, import the landlab package and check its version.

>>> import landlab
>>> landlab.__version__
'2.10.2.dev0'

That’s it!

1 Like

Nice! I’m curious if you’ve tried out using GCC compilers via Conda Forge on Windows? E.g. Anaconda.org. It might avoid needing to install VS. Having said that, I’ve always hit issues trying to do this for GFortran on Windows.

1 Like

Oh, that’s a great idea! I just tried it this morning and it works beautifully. I especially like how this keeps all dependencies, including the compiler and linker, within conda-forge.

I think using gcc should be the preferred method. I’ll write it up.

1 Like

I’m glad it worked well for you! I feel like slowly but surely, development on Windows is getting easier. (Windows Subsystem for Linux helps, but we’re now allowed to use it for cybersecurity reasons!)

1 Like