Anaconda allows for the creation of virtual python environments to segment dependencies.
Download and install Anaconda Individual Edition
Make sure to install it to a path with no spaces
Once installed, open the Anaconda Prompt application and create a new virtual environment. All the commands below will use this prompt.
$ conda create -n QuantConnect python=3.6
According to the documentation, the python implementation of LEAN runs on 3.6
Next install the wrapt
and pandas
packages to the environment
$ conda install -n QuantConnect wrapt=1.11.2
$ conda install -n QuantConnect pandas
Lastly switch over to the QuantConnect
environment and install quantconnect-stubs
via pip
$ conda activate QuantConnect
$ pip install quantconnect-stubs
pip
is installed with Anaconda by default
Download and install Skylight from QuantConnect. The installation is silent and appears in the system tray when complete.
Right click the Skylight icon in the system tray and Log In. Once logged in the projects from your QuantConnect account should be available to you in C:\Users\[Username]\QuantConnect
Skylight is similar in functionality to the Google Drive desktop application that syncs folders to the cloud.
The Pylance extension is needed for python code completion
Open a project from the QuantConnect sync folder. Once open VS Code should recognize the python code and assign an interpreter. It doesn't matter if you already had python installed because you can simply point to the interpreter for your virtual environment.
Click the bottom left corner where the interpreter and its version is displayed
A dropdown should appear in the top center of the app.
Choose Enter interpreter path...
and use the file explorer dialog to navigate to your Anaconda3 installation folder. Inside that folder you'll find env/QuantConnect/python.exe
if you correctly followed the steps to create a virtual environment. Choose that executable as the python interpreter.
The final step is to add the python imports to your projects
from QuantConnect import *
from QuantConnect.Parameters import *
from QuantConnect.Benchmarks import *
from QuantConnect.Brokerages import *
from QuantConnect.Util import *
from QuantConnect.Interfaces import *
from QuantConnect.Algorithm import *
from QuantConnect.Algorithm.Framework import *
from QuantConnect.Algorithm.Framework.Selection import *
from QuantConnect.Algorithm.Framework.Alphas import *
from QuantConnect.Algorithm.Framework.Portfolio import *
from QuantConnect.Algorithm.Framework.Execution import *
from QuantConnect.Algorithm.Framework.Risk import *
from QuantConnect.Indicators import *
from QuantConnect.Data import *
from QuantConnect.Data.Consolidators import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Fundamental import *
from QuantConnect.Data.Market import *
from QuantConnect.Data.UniverseSelection import *
from QuantConnect.Notifications import *
from QuantConnect.Orders import *
from QuantConnect.Orders.Fees import *
from QuantConnect.Orders.Fills import *
from QuantConnect.Orders.Slippage import *
from QuantConnect.Scheduling import *
from QuantConnect.Securities import *
from QuantConnect.Securities.Equity import *
from QuantConnect.Securities.Forex import *
from QuantConnect.Securities.Interfaces import *
from datetime import date, datetime, timedelta
from QuantConnect.Python import *
from QuantConnect.Storage import *
QCAlgorithmFramework = QCAlgorithm
QCAlgorithmFrameworkBridge = QCAlgorithm
The above imports are hidden in the web IDE on QuantConnect but are required for full access to the API in your projects.
Autocomplete within VS Code should now be available; not only for the QuantConnect API but also pandas
and numpy
.
If using an IDE other than VS Code and that IDE doesn't let you select the interpreter to use, set the PYTHONHOME
environment variable to the env/QuantConnect/
folder located inside the Anaconda3 is installation directory.
If the IDE does allow setting the python interpreter, then setting that to the QuantConnect virtual environment (executable) should be all that is needed to get autocompletion working correctly.