I'm trying to run a python algorithm locally on my Windows but got the error below. I did follow the instructions for adding python support already so don't know what else am I missing. The C# version was running fine. Anyone has any idea on how to fix this?
20210909 11:45:46.623 ERROR:: Loader.TryCreatePythonAlgorithm(): System.TypeInitializationException: The type initializer for 'Delegates' threw an exception.
---> System.MissingMethodException: Failed to load symbol PyDictProxy_New
---> System.ComponentModel.Win32Exception (127): The specified procedure could not be found.
--- End of inner exception stack trace ---
at Python.Runtime.Platform.WindowsLoader.GetFunction(IntPtr hModule, String procedureName)
at Python.Runtime.Runtime.Delegates.GetFunctionByName(String functionName, IntPtr libraryHandle)
at Python.Runtime.Runtime.Delegates..cctor()
--- End of inner exception stack trace ---
at Python.Runtime.Runtime.Delegates.get_Py_IsInitialized()
at Python.Runtime.Runtime.Py_IsInitialized()
at Python.Runtime.Runtime.Initialize(Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv, Boolean initSigs, ShutdownMode mode)
at Python.Runtime.PythonEngine.Initialize()
at QuantConnect.Python.PythonInitializer.Initialize() in D:\Lean\Common\Python\PythonInitializer.cs:line 45
at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in D:\Lean\AlgorithmFactory\Loader.cs:line 171
20210909 11:45:46.646 ERROR:: Engine.Run(): QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module QuantConnect.Algorithm.CSharp.dll. The type initializer for 'Delegates' threw an exception.
at QuantConnect.Lean.Engine.Setup.BacktestingSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in D:\Lean\Engine\Setup\BacktestingSetupHandler.cs:line 104
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in D:\Lean\Engine\Engine.cs:line 116
Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module QuantConnect.Algorithm.CSharp.dll. The type initializer for 'Delegates' threw an exception. Stack Trace: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module QuantConnect.Algorithm.CSharp.dll. The type initializer for 'Delegates' threw an exception.
During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module QuantConnect.Algorithm.CSharp.dll. The type initializer for 'Delegates' threw an exception.
Martin Molinero
Hey Reduktion !
> Unable to import python module QuantConnect.Algorithm.CSharp.dll. The type initializer for 'Delegates' threw an exception.
Seems you need to adjust your config.json: ‘QuantConnect.Algorithm.CSharp.dll’ value isn't right, probably ‘algorithm-location’ value in the json, see https://github.com/QuantConnect/Lean/blob/master/Launcher/config.json#L18-L19.
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.
Reduktion
Hi Martin,
thanks for the reply. If I change the relevant part in D:\Lean\Launcher\config.json to
I still get the error:
Reduktion
And before above mentioned error, I receive also:
Martin Molinero
Hey Reduktion !
Every time I've seen that error it's because lean python is not setup, have you followed the steps at https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/readme.md#setup-lean-locally-with-python . Usually it's environment variable ‘PYTHONNET_PYDLL’ that's not set.
Suggest directly using the Lean CLI if it fits your use case, see https://www.lean.io/cli/
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.
Reduktion
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!