Installing Lean CLI


The Lean CLI is distributed as a Python package, so it requires pip to be installed. See Installing pip to learn how to install pip on your operating system.

The commands which run the LEAN engine locally also depend on Docker being installed and running. See Installing Docker to learn how to install Docker on your operating system.


After installing pip, run pip install lean to install the Lean CLI. This commands downloads all the CLI's dependencies and makes the lean command available in the terminal.

After installing the CLI, open a terminal in an empty directory and run lean init. This command scaffolds a standard directory structure containing a data directory and a Lean configuration file, both of which are required to run the LEAN engine locally. We recommend running all Lean CLI commands in the same directory lean init was ran in.

If you are running Docker on Windows using the legacy Hyper-V backend instead of the new WSL 2 backend, you also need to enable file sharing for your temporary directories and for the directory you ran lean init in. To do so, open your Docker settings, go to Resources > File sharing and add C:/Users/<username>/AppData/Local/Temp and the directory you ran lean init in to the list. Click Apply & Restart after making the required changes.

Staying up-to-date

We regularly update the CLI to add new features and to fix issues. It is therefore important to keep both the CLI and the Docker images that the CLI uses up-to-date.

Keeping the CLI up-to-date

Run pip install --upgrade lean to update the CLI to the latest version. The CLI automatically performs a version check once a day and warns you in case you are running an outdated version.

Keeping the Docker images up-to-date

Various commands like lean backtest, lean optimize and lean research run the LEAN engine in a Docker container to ensure all the required dependencies are available. When you run these commands for the first time the Docker image containing LEAN and its dependencies is downloaded and stored. Run these commands with the --update flag to update the images they use. Additionally, these commands automatically perform a version check once a week and update the image they use when you are using an outdated Docker image.


Run pip uninstall lean to uninstall the Lean CLI. To perform a full uninstallation you must also delete configuration files generated by the CLI. These might be found in the following directories:

  • The .lean directory in your user's home directory.
  • The directories you ran the lean init, lean create-project and/or lean cloud pull commands in.

You can also see our Videos. You can also get in touch with us via Chat.

Did you find this page helpful?

Contribute to the documentation: