Using Lean with Visual Studio 2017 and Anaconda3

Hello everyone

I am trying to use Anaconda3 which comes bundled together with Visual Studio 2017 with Lean. I have therfor checked the latest version from git, installed the Python development tools together with Visual Studios Anaconda. This are the steps I have walked through:

1. Read Python introduction on github

2. Installed Python development tools using Visual Studio 2017 installer including Anaconda3 (version 5.1.0)

3. Extended PATH system variable to point to python36.dll which resides in C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64. Please note: I havent modified/created PYTHONPATH/PYTHONHOME as it breaks my current Python development environment in Visual Studio. 

4. Copied "Build/Python.Runtime.Win" to "Lib/Python.Runtime.dll"

5. Cleaned the solution and did a complete fresh rebuild of the entire solution ("Rebuild solution") 

6. Modified the config.json file accordingly 

7. Set Anaconda to be the system default python environment 

From this point on I am able to run the python example algorithms. 

However it cant find my anaconda libraries. Can someone please give me a helping hand here? What do the PYTHONPATH and PYTHONHOME need to look like in my case? This is so confusing. 

Thanks a lot in advance!!!!!

20180710 15:55:58.510 ERROR:: Loader.TryCreatePythonAlgorithm():  System.Exception: AlgorithmPythonWrapper(): ModuleNotFoundError : No module named 'pandas' ModuleNotFoundError : No module named 'pandas'
   bei QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) in C:\Dev\Projects\Lean\AlgorithmFactory\Python\Wrappers\AlgorithmPythonWrapper.cs:Zeile 103.
   bei QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in C:\Dev\Projects\Lean\AlgorithmFactory\Loader.cs:Zeile 172.
20180710 15:55:58.660 ERROR:: Engine.Run():  QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/ AlgorithmPythonWrapper(): ModuleNotFoundError : No module named 'pandas' ModuleNotFoundError : No module named 'pandas'
   bei QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\Dev\Projects\Lean\Engine\Setup\ConsoleSetupHandler.cs:Zeile 92.
   bei QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\Dev\Projects\Lean\Engine\Engine.cs:Zeile 115.

Update Backtest

Whats also surprising is that Visual Studio is complaining about other modules being missing


There are several websites, blogs and stackexchange posts that clearly vote against the use of PYTHONHOME.  Shouldnt it be enough to set PATH to point to the python36.dll / python.exe / pythonw.exe? 

I also noticed Visual Studio 2017 having an option called "Ignore system-wide PYTHONPATH variables". I have ensured its unchecked (as oppossed to its default) 

The more I read about this python variables the more I get confused. Any Windows examples on this would be really great. 

I would like to update the documentation on GitHub for this issue as soon I have solved it. 


After many hours of fiddling around with Visual Studio I found a way of using the python package that gets provided by Visual Studios 2017 to work with Lean, that I would like to share with the community. I wasnt able to get Anaconda3 working, however my main goal was getting a plotting functionality/library like seaborn and matplotlib to work with the OpenSource version anyway, so no specific need for Anaconda3 (currently).   

Things I have learned: 

  • You wont have to set PYTHONPATH nor PYTHONHOME when using VS packages 
  • It's enough to extend your PATH variable so it points to the directory holding python.exe, pythonw.exe and python36.dll
  • In case you have messed up your working environment try to uninstall the NuGet package QuantConnect.pythonnet for all projects and install it again

Things still unclear to me: 

  • Where should I create the dataset for plotting? Within OnData(self, data)? ¨
  • How can I make non-blocking 

 Here is the step by step approach I took: 

  1. Install Python3 support using the Visual Studio installer (x64 and version 3.6.5 in my case)
  2. In case you have other Python environments installed, set the version installed under point 1. as the default environment for new projects
  3. Within "Python Environments" switch to "Packages (PyPi)" and install the following packages: seaborn and pandas. Ensure all modules are up to date. In my case updating "pip" and other packages was necesarry. 
  4. Switch to IntelliSense and hit "Refresh DB", this will take a while, but give you IntelliSense support for the installed modules 
  5. Create a new Python project and create a small test plot to ensure everything is working. You can refer to the example library which can be found here. When creating a chart don't forget to use "" otherwise nothing will be visible. 
  6. Copy the \Lean\packages\QuantConnect.pythonnet.\build\ file into the ..\lib\ directory and rename it to Python.Runtime.dll
  7. Update config,json according to the official manual 
  8. On the entire solution, hit "Clean Solution" and then "Rebuild solution", to ensure you are using the new Python.Runtime.dll 
  9. Later on you should be able to use matplotlib and seaborn in your algorithms. 

Update Backtest


The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


This discussion is closed