Skip to content

Keep getting error for Python support #6496

@mit10000

Description

@mit10000

Followed instructions here
https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#python-autocomplete-imports
OS: Ubuntu 16.04
Already installed dotnet-sdk-6.0, and we could do
dotnet build QuantConnect.Lean.sln
dotnet QuantConnect.Lean.Launcher.dll
and get STATISTICS. Seems C# is running OK.

Tried to use Python:
1 create new enviroment
conda create -n qc_lean python=3.6.8 cython=0.29.11 pandas=0.25.3 wrapt=1.11.2
2 add new line to /etc/environment
PYTHONNET_PYDLL="/home/myname/anaconda3/envs/qc_lean/lib/libpython3.6m.so"
3 change Lean/Launcher/config.json
"algorithm-type-name": "BasicTemplateFrameworkAlgorithm",
"algorithm-language": "Python",//"CSharp",
"algorithm-location": "../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py",
4 rebuild, rerun
dotnet clean
dotnet build QuantConnect.Lean.sln
dotnet QuantConnect.Lean.Launcher.dll
Then got ERRORS

20220720 14:33:11.899 TRACE:: Config.GetValue(): debug-mode - Using default value: False
20220720 14:33:11.925 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value:
20220720 14:33:11.925 TRACE:: Config.Get(): Configuration key not found. Key: plugin-directory - Using default value:
20220720 14:33:11.927 TRACE:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default value:
20220720 14:33:11.929 TRACE:: Composer(): Loading Assemblies from /home/name/Projects/LEAN/Lean/Launcher/bin/Debug/
20220720 14:33:11.980 TRACE:: Python for .NET Assembly: Python.Runtime, Version=2.0.16.0, Culture=neutral, PublicKeyToken=5000fea6cba702dd
20220720 14:33:12.001 TRACE:: Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
20220720 14:33:12.026 TRACE:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20220720 14:33:12.026 TRACE:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: ../../../Data/
20220720 14:33:12.026 TRACE:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.5.0.0 Mode: DEBUG (64bit) Host: my-ubuntu
20220720 14:33:12.036 TRACE:: Engine.Main(): Started 10:33 AM
20220720 14:33:12.040 TRACE:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager
20220720 14:33:12.055 TRACE:: JobQueue.NextJob(): Selected ../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py
20220720 14:33:12.113 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-capacity - Using default value: 120
20220720 14:33:12.113 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-time-interval-minutes - Using default value: 1440
20220720 14:33:12.113 TRACE:: Config.GetValue(): scheduled-event-leaky-bucket-refill-amount - Using default value: 18
20220720 14:33:12.113 TRACE:: Config.GetValue(): storage-limit-mb - Using default value: 5
20220720 14:33:12.113 TRACE:: Config.GetValue(): storage-file-count - Using default value: 100
20220720 14:33:12.113 TRACE:: Config.GetValue(): storage-permissions - Using default value: 3
20220720 14:33:12.113 TRACE:: Config.Get(): Configuration key not found. Key: algorithm-id - Using default value: BasicTemplateFrameworkAlgorithm
20220720 14:33:12.137 TRACE:: Config.GetValue(): job-project-id - Using default value: 0
20220720 14:33:12.138 TRACE:: Config.Get(): Configuration key not found. Key: data-permission-manager - Using default value: DataPermissionManager
20220720 14:33:12.139 TRACE:: Config.Get(): Configuration key not found. Key: results-destination-folder - Using default value: /home/name/Projects/LEAN/Lean/Launcher/bin/Debug
20220720 14:33:12.147 TRACE:: Config.Get(): Configuration key not found. Key: object-store-root - Using default value: ./storage
20220720 14:33:12.150 TRACE:: AlgorithmManager.CreateTokenBucket(): Initializing LeakyBucket: Capacity: 120 RefillAmount: 18 TimeInterval: 1440
20220720 14:33:12.152 TRACE:: Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 20
20220720 14:33:12.158 TRACE:: TextSubscriptionDataSourceReader.SetCacheSize(): Setting cache size to 71582788 items
20220720 14:33:12.392 TRACE:: Config.GetValue(): algorithm-creation-timeout - Using default value: 90
20220720 14:33:12.393 TRACE:: PythonInitializer.Initialize(): start...
20220720 14:33:12.470 ERROR:: Loader.TryCreatePythonAlgorithm(): Python.Runtime.BadPythonDllException: Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net
---> System.MissingMethodException: Failed to load symbol Py_IncRef: dotnet: undefined symbol: Py_IncRef
at Python.Runtime.Platform.PosixLoader.GetFunction(IntPtr dllHandle, String name)
at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle)
--- End of inner exception stack trace ---
at Python.Runtime.Runtime.TryUsingDll[T](Func1 op) at Python.Runtime.Runtime.Initialize(Boolean initSigs) at Python.Runtime.PythonEngine.Initialize(IEnumerable1 args, Boolean setSysArgv, Boolean initSigs)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs)
at Python.Runtime.PythonEngine.Initialize()
at QuantConnect.Python.PythonInitializer.Initialize() in /home/name/Projects/LEAN/Lean/Common/Python/PythonInitializer.cs:line 45
at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in /home/name/Projects/LEAN/Lean/AlgorithmFactory/Loader.cs:line 171
20220720 14:33:12.471 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/BasicTemplateFrameworkAlgorithm.py. Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in /home/name/Projects/LEAN/Lean/Engine/Setup/BacktestingSetupHandler.cs:line 103
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in /home/name/Projects/LEAN/Lean/Engine/Engine.cs:line 115
20220720 14:33:12.471 TRACE:: JOB HANDLERS:
20220720 14:33:12.471 TRACE:: DataFeed: QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
20220720 14:33:12.471 TRACE:: Setup: QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler
20220720 14:33:12.471 TRACE:: RealTime: QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
20220720 14:33:12.471 TRACE:: Results: QuantConnect.Lean.Engine.Results.BacktestingResultHandler
20220720 14:33:12.471 TRACE:: Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20220720 14:33:12.471 TRACE:: Alpha: QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20220720 14:33:12.471 TRACE:: ObjectStore: QuantConnect.Lean.Engine.Storage.LocalObjectStore
20220720 14:33:12.472 TRACE:: DefaultAlphaHandler.Exit(): Exiting...
20220720 14:33:12.473 TRACE:: DefaultAlphaHandler.Exit(): Ended
20220720 14:33:12.473 TRACE:: BacktestingResultHandler.Exit(): starting...
20220720 14:33:12.473 TRACE:: BacktestingResultHandler.Exit(): Saving logs...
20220720 14:33:12.475 TRACE:: StopSafely(): waiting for 'Result Thread' thread to stop...
20220720 14:33:12.475 ERROR:: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py. Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net Stack Trace: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py. Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net
During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py. Runtime.PythonDLL was not set or does not point to a supported Python runtime DLL. See https://github.com/pythonnet/pythonnet#embedding-python-in-net
20220720 14:33:12.475 TRACE:: Debug: Your log was successfully created and can be retrieved from: /home/name/Projects/LEAN/Lean/Launcher/bin/Debug/BasicTemplateFrameworkAlgorithm-log.txt
20220720 14:33:12.475 TRACE:: BacktestingResultHandler.Run(): Ending Thread...
20220720 14:33:12.570 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
20220720 14:33:12.571 TRACE:: BacktestingResultHandler.SendAnalysisResult(): Processed final packet
20220720 14:33:12.571 TRACE:: Engine.Run(): Disposing of setup handler...
20220720 14:33:12.571 TRACE:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete.
20220720 14:33:12.571 TRACE:: Config.GetValue(): close-automatically - Using default value: False
Engine.Main(): Press any key to continue.

20220720 14:33:16.028 TRACE:: Engine.Main(): Packet removed from queue: BasicTemplateFrameworkAlgorithm
20220720 14:33:16.028 TRACE:: LeanEngineSystemHandlers.Dispose(): start...
20220720 14:33:16.028 TRACE:: LeanEngineSystemHandlers.Dispose(): Disposed of system handlers.
20220720 14:33:16.029 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): start...
20220720 14:33:16.029 TRACE:: LeanEngineAlgorithmHandlers.Dispose(): Disposed of algorithm handlers.
20220720 14:33:16.029 TRACE:: StopSafely(): waiting for 'CpuPerformance' thread to stop...
20220720 14:33:16.029 TRACE:: Program.Main(): Exiting Lean...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions