Hi -
I have performed all steps mentioned here, and all steps have been successful. Howver when I run a local backtest, i get the below error. What am I missing? Please note: If i run the cloud backtest via CLI - it runs fine, its just the local backtest that is causing some issues.
20210612 15:18:27.379 ERROR:: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python
module /LeanCLI/main.py. AlgorithmPythonWrapper(): NameError :20210612 15:18:27.379 TRACE:: DefaultAlphaHandler.Exit(): Ended
name 'Resolution' is not defined
Rakesh Gopal
Error Trace:
(base) c:\Quantconnect\Lean>lean cloud pull --project "localbacktestingexample"
[1/1] Pulling 'localbacktestingexample'
Successfully pulled 'localbacktestingexample/main.py'
(base) c:\Quantconnect\Lean>lean backtest "localbacktestingexample"
←[?1h←=20210612 15:51:47.362 TRACE:: Config.GetValue(): debug-mode - Using default value: False
20210612 15:51:47.376 TRACE:: Config.Get(): Configuration key not found. Key: plugin-directory - Using default value:
20210612 15:51:47.488 TRACE:: Python for .NET Assembly: Python.Runtime, Version=2.0.3.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd
20210612 15:51:47.507 TRACE:: Python for .NET Assembly: nPython, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null
20210612 15:51:47.565 TRACE:: Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
20210612 15:51:47.573 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20210612 15:51:47.574 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: /Lean/Data
20210612 15:51:47.575 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) Host: BELR90TN65Z
20210612 15:51:47.584 TRACE:: Engine.Main(): Started 3:51 PM
20210612 15:51:47.590 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager
20210612 15:51:47.640 TRACE:: JobQueue.NextJob(): Selected /LeanCLI/main.py
20210612 15:51:47.783 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-capacity - Using default value: 120
20210612 15:51:47.783 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-time-interval-minutes - Using default value: 1440
20210612 15:51:47.784 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-refill-amount - Using default value: 18
20210612 15:51:47.787 TRACE:: Config.Get(): Configuration key not found. Key: algorithm-id - Using default value: main
20210612 15:51:47.794 TRACE:: Config.GetValue(): job-project-id - Using default value: 0
20210612 15:51:47.795 TRACE:: Config.Get(): Configuration key not found. Key: data-permission-manager - Using default value: DataPermissionManager
20210612 15:51:47.823 TRACE:: AlgorithmManager.CreateTokenBucket(): Initializing LeakyBucket: Capacity: 120 RefillAmount: 18 TimeInterval: 1440
20210612 15:51:47.826 TRACE:: Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 20
20210612 15:51:47.840 TRACE:: TextSubscriptionDataSourceReader.SetCacheSize(): Setting cache size to 71582788 items
20210612 15:51:48.510 TRACE:: Config.GetValue(): algorithm-creation-timeout - Using default value: 90
20210612 15:51:48.519 TRACE:: PythonInitializer.Initialize(): start...
PythonEngine.Initialize(): Runtime.Initialize()...
Runtime.Initialize(): Py_Initialize...
Runtime.Initialize(): PyEval_InitThreads...
Runtime.Initialize(): Initialize types...
Runtime.Initialize(): Initialize types end.
Runtime.Initialize(): AssemblyManager.Initialize()...
Runtime.Initialize(): AssemblyManager.UpdatePath()...
PythonEngine.Initialize(): GetCLRModule()...
PythonEngine.Initialize(): clr GetManifestResourceStream...
20210612 15:51:50.675 TRACE:: PythonInitializer.Initialize(): ended
20210612 15:51:50.681 TRACE:: AlgorithmPythonWrapper(): Python version 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:25:33)
[GCC 7.3.0]: Importing python module main
20210612 15:51:51.343 ERROR:: Loader.TryCreatePythonAlgorithm(): System.Exception: AlgorithmPythonWrapper(): NameError : name 'QCAlgorithm' is not defined
at <module>
class CryingMagentaElephant(QCAlgorithm):
===
at Python.Runtime.PythonException.ThrowIfIsNull(IntPtr ob)
at Python.Runtime.PythonEngine.ImportModule(String name)
at Python.Runtime.Py.Import(String name)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) at
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 74 in main.py:line 1
NameError : name 'QCAlgorithm' is not defined
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 146
at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Loader.cs:line 173
20210612 15:51:51.345 ERROR:: Engine.Run(): QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred:
Loader.TryCreatePythonAlgorithm(): Unable to import python module /LeanCLI/main.py. AlgorithmPythonWrapper(): NameError : name 'QCAlgorithm' is not defined
at <module>
class CryingMagentaElephant(QCAlgorithm):
===
at Python.Runtime.PythonException.ThrowIfIsNull(IntPtr ob)
at Python.Runtime.PythonEngine.ImportModule(String name)
at Python.Runtime.Py.Import(String name)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) at
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 74 in main.py:line 1
NameError : name 'QCAlgorithm' is not defined
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/Setup/BacktestingSetupHandler.cs:line 104
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Engine/Engine.cs:line 119
20210612 15:51:51.347 TRACE:: JOB HANDLERS:
20210612 15:51:51.348 TRACE:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
20210612 15:51:51.348 TRACE:: Setup: QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler
20210612 15:51:51.350 TRACE:: RealTime: QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
20210612 15:51:51.350 TRACE:: Results: QuantConnect.Lean.Engine.Results.BacktestingResultHandler
20210612 15:51:51.351 TRACE:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20210612 15:51:51.352 TRACE:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20210612 15:51:51.352 TRACE:: ObjectStore: QuantConnect.Lean.Engine.Storage.LocalObjectStore
20210612 15:51:51.354 TRACE:: DefaultAlphaHandler.Exit(): Exiting...
20210612 15:51:51.356 TRACE:: DefaultAlphaHandler.Exit(): Ended
20210612 15:51:51.357 TRACE:: BacktestingResultHandler.Exit(): starting...
20210612 15:51:51.358 TRACE:: BacktestingResultHandler.Exit(): Saving logs...
20210612 15:51:51.368 TRACE:: StopSafely(): waiting for 'Result Thread' thread to stop...
20210612 15:51:51.371 ERROR:: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python
module /LeanCLI/main.py. AlgorithmPythonWrapper(): NameError : name 'QCAlgorithm' is not defined
at <module>
class CryingMagentaElephant(QCAlgorithm):
===
at Python.Runtime.PythonException.ThrowIfIsNull(IntPtr ob)
at Python.Runtime.PythonEngine.ImportModule(String name)
at Python.Runtime.Py.Import(String name)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) at
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 74 in main.py:line 1
NameError : name 'QCAlgorithm' is not defined Stack Trace: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module
/LeanCLI/main.py. AlgorithmPythonWrapper(): NameError : name 'QCAlgorithm' is not defined
at <module>
class CryingMagentaElephant(QCAlgorithm):
===
at Python.Runtime.PythonException.ThrowIfIsNull(IntPtr ob)
at Python.Runtime.PythonEngine.ImportModule(String name)
at Python.Runtime.Py.Import(String name)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) at
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 74 in main.py:line 1
NameError : name 'QCAlgorithm' is not defined
During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module /LeanCLI/main.py. AlgorithmPythonWrapper(): NameError : name
'QCAlgorithm' is not defined
at <module>
class CryingMagentaElephant(QCAlgorithm):
===
at Python.Runtime.PythonException.ThrowIfIsNull(IntPtr ob)
at Python.Runtime.PythonEngine.ImportModule(String name)
at Python.Runtime.Py.Import(String name)
at QuantConnect.AlgorithmFactory.Python.Wrappers.AlgorithmPythonWrapper..ctor(String moduleName) at
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/AlgorithmFactory/Python/Wrappers/AlgorithmPythonWrapper.cs:line 74 in main.py:line 1
NameError : name 'QCAlgorithm' is not defined
20210612 15:51:51.372 TRACE:: Debug: Your log was successfully created and can be retrieved from: /Results/main-log.txt
20210612 15:51:51.372 TRACE:: BacktestingResultHandler.Run(): Ending Thread...
20210612 15:51:51.545 TRACE:: Config.GetValue(): regression-update-statistics - Using default value: False
20210612 15:51:51.548 TRACE::
STATISTICS:: Fitness Score 0
STATISTICS:: Kelly Criterion Estimate 0
STATISTICS:: Kelly Criterion Probability Value 0
STATISTICS:: Sortino Ratio 0
STATISTICS:: Return Over Maximum Drawdown 0
STATISTICS:: Portfolio Turnover 0
STATISTICS:: Total Insights Generated 0
STATISTICS:: Total Insights Closed 0
STATISTICS:: Total Insights Analysis Completed 0
STATISTICS:: Long Insight Count 0
STATISTICS:: Short Insight Count 0
STATISTICS:: Long/Short Ratio 100%
STATISTICS:: Estimated Monthly Alpha Value $0
STATISTICS:: Total Accumulated Estimated Alpha Value $0
STATISTICS:: Mean Population Estimated Insight Value $0
STATISTICS:: Mean Population Direction 0%
STATISTICS:: Mean Population Magnitude 0%
STATISTICS:: Rolling Averaged Population Direction 0%
STATISTICS:: Rolling Averaged Population Magnitude 0%
STATISTICS:: OrderListHash d41d8cd98f00b204e9800998ecf8427e
20210612 15:51:51.549 TRACE:: BacktestingResultHandler.SendAnalysisResult(): Processed final packet
20210612 15:51:51.550 TRACE:: Engine.Run(): Disposing of setup handler...
20210612 15:51:51.551 TRACE:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete.
20210612 15:51:51.553 TRACE:: Engine.Main(): Packet removed from queue: main
20210612 15:51:51.554 TRACE:: LeanEngineSystemHandlers.Dispose(): start...
20210612 15:51:51.555 TRACE:: LeanEngineSystemHandlers.Dispose(): Disposed of system handlers.
20210612 15:51:51.556 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): start...
20210612 15:51:51.557 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.
20210612 15:51:51.560 TRACE:: Program.Main(): Exiting Lean...
Error: Something went wrong while running 'localbacktestingexample' in the 'backtesting' environment, the output is stored in 'localbacktestingexample\backtests\2021-06-12_08-51-45'
Jasper van Merle
Hi Rakesh,
In the cloud a lot of imports are applied to your files automatically, while locally you need to manually import all the classes and enums that your code uses. See the CLI documentation for the full list of imports that is added to your code when it is running in the cloud.
Rakesh Gopal
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!