Here is the debug msg:
2018-10-29T17:55:59.5097221Z Error Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateFrameworkAlgorithm.py. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Stack Trace: 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. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 94
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\QC\Lean-master\Engine\Engine.cs:line 115
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. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 94
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\QC\Lean-master\Engine\Engine.cs:line 115
However, I do have python 3.6.5 installed on my machine:
An idea what might went wrong?
GregasMaximus
Did you figure this out? Also running into a similiar issue. I tried upgrading to python 3.6.6, re-running setup.py and rebuilding, but no help.
GregasMaximus
After a bunch googling, trying to understand the situation, I found that python3.6m.dll is simply the python dll, with a python-optimized malloc(). I'm still not sure how I was supposed to get the library (is it supposed to come with the python dist or do I build it?). However, I think that I have found a solution (lightly tested). I simply copied python36.dll to python3.6m.dll. Now it runs and the BasicTemplateFrameworkAlgorithm gives the same result as the C# version.
- Using a link would probably work, I did not try; I just copied
- There may be a performance penalty because you the malloc() function is not optimized for Python access patterns. But at least it works (so far)
Alexandre Catarino
Thanks, GregasMaximus.
Here is the link to the thread with your solution: Running local python algorithm error #4252.
Bor M
HiÂ
I have followed all of the steps for instaillation but still can run Quantconnect via python in my VS2017. I am on win 10 machine.
I am still getting the same error(can find python3,6m.dll). even after renaming copying and renamin python36.dll into python3.6m.dll in my Anaconda3 folder.
Â
See below for error. I am trying to figure out an issue for the past 2 days but I just cant resolve it.
Â
20190622 21:18:11.908 Trace:: Config.GetValue(): debug-mode - Using default value: False
20190622 21:18:11.996 Trace:: Config.Get(): Configuration key not found. Key: plugin-directory - Using default value:
20190622 21:18:11.999 Trace:: Config.Get(): Configuration key not found. Key: composer-dll-directory - Using default value: C:\Users\rasal\Source\Repos\LEAN\Launcher\bin\Debug\
20190622 21:18:14.242 Trace:: Config.Get(): Configuration key not found. Key: data-directory - Using default value: ../../../Data/
20190622 21:18:14.268 Trace:: Config.Get(): Configuration key not found. Key: version-id - Using default value:
20190622 21:18:14.269 Trace:: Config.Get(): Configuration key not found. Key: cache-location - Using default value: ../../../Data/
20190622 21:18:14.270 Trace:: Engine.Main(): LEAN ALGORITHMIC TRADING ENGINE v2.4.0.0 Mode: DEBUG (64bit)
20190622 21:18:14.270 Trace:: Engine.Main(): Started 9:18 PM
20190622 21:18:14.273 Trace:: Config.GetValue(): job-project-id - Using default value: 0
20190622 21:18:14.274 Trace:: Config.Get(): Configuration key not found. Key: algorithm-path-python - Using default value: ../../../Algorithm.Python/
20190622 21:18:14.276 Trace:: Config.GetValue(): regression-update-statistics - Using default value: False
20190622 21:18:14.277 Trace:: Config.Get(): Configuration key not found. Key: lean-manager-type - Using default value: LocalLeanManager
20190622 21:18:14.326 Trace:: Config.Get(): Configuration key not found. Key: cloud-api-url - Using default value: https://www.quantconnect.com/api/v2/
20190622 21:18:14.344 Trace:: JobQueue.NextJob(): Selected ../../../Algorithm.Python/BasicTemplateAlgorithm.py
20190622 21:18:14.663 Trace:: Config.GetValue(): ignore-version-checks - Using default value: False
20190622 21:18:14.666 Trace:: Config.GetValue(): algorithm-manager-time-loop-maximum - Using default value: 20
20190622 21:18:14.702 Trace:: Python for .NET Assembly: Python.Runtime, Version=1.0.5.20, Culture=neutral, PublicKeyToken=null
20190622 21:18:15.380 Trace:: Python for .NET Assembly: nPython, Version=1.0.5.20, Culture=neutral, PublicKeyToken=null
20190622 21:18:15.587 ERROR:: Loader.TryCreatePythonAlgorithm(): Â System.DllNotFoundException: Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  at Python.Runtime.Runtime.Py_IsInitialized()
  at Python.Runtime.Runtime.Initialize()
  at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv)
  at Python.Runtime.PythonEngine.Initialize()
  at QuantConnect.Python.PythonInitializer.Initialize() in C:\Users\rasal\Source\Repos\LEAN\Common\Python\PythonInitializer.cs:line 36
  at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in C:\Users\rasal\Source\Repos\LEAN\AlgorithmFactory\Loader.cs:line 174
20190622 21:18:15.667 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/BasicTemplateAlgorithm.py. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Setup\ConsoleSetupHandler.cs:line 97
  at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Engine.cs:line 131
20190622 21:18:15.674 Trace:: JOB HANDLERS:
20190622 21:18:15.674 Trace:: Â Â Â Â Â DataFeed: Â Â QuantConnect.Lean.Engine.DataFeeds.FileSystemDataFeed
20190622 21:18:15.675 Trace:: Â Â Â Â Â Setup: Â Â Â Â QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler
20190622 21:18:15.675 Trace:: Â Â Â Â Â RealTime: Â Â QuantConnect.Lean.Engine.RealTime.BacktestingRealTimeHandler
20190622 21:18:15.676 Trace:: Â Â Â Â Â Results: Â Â Â QuantConnect.Lean.Engine.Results.BacktestingResultHandler
20190622 21:18:15.677 Trace:: Â Â Â Â Â Transactions: QuantConnect.Lean.Engine.TransactionHandlers.BacktestingTransactionHandler
20190622 21:18:15.678 Trace:: Â Â Â Â Â Alpha: Â Â Â Â QuantConnect.Lean.Engine.Alphas.DefaultAlphaHandler
20190622 21:18:15.700 Trace:: Waiting for threads to exit...
20190622 21:18:15.707 Trace:: Config.GetValue(): send-via-api - Using default value: False
20190622 21:18:15.717 ERROR:: Algorithm.Initialize() Error: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Stack Trace: QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Setup\ConsoleSetupHandler.cs:line 97
  at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Engine.cs:line 131
 QuantConnect.Lean.Engine.Setup.AlgorithmSetupException: During the algorithm initialization, the following exception has occurred: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. Unable to load DLL 'python3.6m': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Setup\ConsoleSetupHandler.cs:line 97
  at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\Users\rasal\Source\Repos\LEAN\Engine\Engine.cs:line 131
20190622 21:18:15.733 Trace:: Debug: Your log was successfully created and can be retrieved from: C:\Users\rasal\Source\Repos\LEAN\Launcher\bin\Debug\BasicTemplateAlgorithm-log.txt
20190622 21:18:15.733 Trace:: BacktestingResultHandler.Run(): Ending Thread...
20190622 21:18:15.744 Trace:: Engine.Run(): Disposing of setup handler...
20190622 21:18:15.745 Trace:: Engine.Main(): Analysis Completed and Results Posted.
Engine.Main(): Analysis Complete. Press any key to continue.
Daniel Chen
Hi Bor,
It’s natural to face some set-up issues, so don’t be too upset.  Some Mac users faced this error before, and they solved it by adding one more configuration to Python.Runtime.dll.config. I believe it works for Windows user too, you can find detailed instruction in section Install Python 3.6 - macOS - Note here.
Make sure you don’t use python 3.7 because Lean currently runs on python 3.6.
If you configure properly, you will see results (statistics) of the algorithm. Make sure you don’t miss any previous configuration step. Thank you for your question and looking forward to your reply!
Bor M
Hi Qilong ,
Thank you for your quick response, It is greatly appreciated!!!
I have tried to follow mac instruction and find my libpython3,6m.dylib in my Anaconda3 folder, but had no luck...I have tried everything on this forums and it looks like i am stuck...Any help would be greatly appreciated!!!
Â
/Users/{your_user_name}/anaconda3/lib/libpython3.6m.dylib
Daniel Chen
Hi Bor,
Could you please check your environmental variables, and make sure Anaconda3 folder is in PATH and also PYTHONHOME?
Bor M
Hi Qilong,
I had to update my VS17 studio, re-did the whole installation step by step and anddd environmental variables and IT WORKED!!!! So happy!!!! Thank you for all your help!!!
One question, I can run python scripts by pressing F5, but is there a way to run them through interactive in VS17?Â
Best,
Bor
Daniel Chen
Hi Bor,
You can find the information on this guide. Good Luck!
Bor M
Thank you Qilong,
The data that you send me just descibes how to run it in interactive. But in these cases it doesnt work is it because it is precompiled in C#. I nasically can import ant reference to Quantconnect?Â
Â
from clr import AddReference
>>> AddReference("System")
<System.Reflection.RuntimeAssembly object at 0x00000205F9E34518>
>>> AddReference("QuantConnect.Algorithm")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'QuantConnect.Algorithm'.
  at Python.Runtime.CLRModule.AddReference(String name)
Daniel Chen
Hi Bor,
It is totally feasible in QuantConnect, but you should import the reference in the same directory where QuantConnect.Algorithm.dll is located, that is, Lean/Launcher/bin/Debug. After you cd to that directory, there will be no bug for the same code you wrote.
Thank you!
Bor M
Hi Daniel,
What do you mean by cd into the directory? I am using BasicTemplateAlgorithm in VS that i can run by pressing F5, but when trying to run code through Interactive I get the following error:
>>> AddReference("QuantConnect.Algorithm")
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
System.IO.FileNotFoundException: Unable to find assembly 'QuantConnect.Algorithm'.
  at Python.Runtime.CLRModule.AddReference(String name)
Â
Can you please explain me what do you mean with cd into directory? I am in VS...so not sure how to do this....
Thank you for all your help and quick responses!
Â
Bor
Daniel Chen
Hi Blackladder,
After seeing your post, I think you are correct on finding the libpython3.6m.dylib path and changing the config file. May I ask where do you install your Anaconda? It should be Anaconda 3 - 5.2.0, and should be downloaded through the link in this page. I am afraid that it is other version of python that causes this issue. Regarding the Mac version, it is possibly not the problem since some users using Mojave 10.14.2 can succeed in installation with the same instructions.Â
Please follow exactly the instructions in these two pages. If this issue still exists, please feel free to let me know. Good luck!
Bor M
Daniel,
I have followed this instructions many time over and I am able to run it by pressing F5, I get the results in a pop-up window. But I would like to run them in Interactive window of my Visual Studio. It is much easier to track for me...Is that even a possibilty given that Quantconnect is written in C#....but I would imagine it should be, since I read you can run it in Jupyter notebooks. Am I missing something?
Â
Best and thank you again for all your help!!
Â
Daniel Chen
Hi Bor,
You're welcome. The idea to use interactive window is really cool, but I am sorry that it is not supported for now. However, using desktop LEAN to debug is also convenient, since you can count on the python debugger in Visual Studio. In this way, you can also track variables easily. Please visit this page for detailed information.
Besides, Â Jupyter Notebook is designed for research. It is very useful and handy to manipulate and work with data in the research environment. Because of this, we don't include the function of backtesting algorithm in the research environment. We recommend you take the advantage of Jupyter Notebook to perform exploratory research and brainstorm new ideas for an algorithm, and then deploy your idea in backtest environment. For your information, please visit here.
We hope you enjoy creating algorithms in QuantConnect! Thank you.
Daniel Chen
Hi Blackladder,
Thank you for your follow-up. I’ve done the whole installation process in my macOS Mojave again following the instructions on the pages I sent you, and I do have these errors information too. However, these errors we met when opening QuantConnect.Lean in the Mac OS system can be ignored.
Could you please use the BasicTemplateAlgorithm.py to test? Please follow the instruction on this page. I believe you will get the statistics for this algorithm, which means your setup is totally correct. Thank you for your patience, and we look forward to your good news!
Blackladder
Hi Daniel,
It worked! It turns out that the devil lies in the version of my python... (previously 3.6.5) I'll just share what I did here in case someone else encounters the problem in the future:
Open terminal -> conda create -n py36 python=3.6.6 anaconda -> conda activate py36
When changing the Python.Runtime.dll.config, the path should be something like this:
"/Users/blackladder/anaconda3/envs/py36/lib/libpython3.6m.dylib"
Then I changed the runtime config as instructed, then rebuild -> run, statistics popped up.
I think they should really specify in the python support the page about the version of python and so on.
Thanks for the help!
Blackladder
Â
Milad Resketi
Got this error when I ran Lean locally, I followed the instaructions inÂ
https://github.com/QuantConnect/Lean/tree/master/Algorithm.Python#quantconnect-python-algorithm-projectbut still getting this error! I'm running it on Windows 10.
20210417 05:10:50.264 ERROR:: Loader.TryCreatePythonAlgorithm(): System.TypeInitializationException: The type initializer for 'Delegates' threw an exception. ---> System.DllNotFoundException: Could not load C:\Anaconda3 ---> System.ComponentModel.Win32Exception: The specified module could not be found --- End of inner exception stack trace --- at Python.Runtime.Platform.WindowsLoader.Load(String dllToLoad) at Python.Runtime.Runtime.Delegates.GetUnmanagedDll(String libraryName) 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 C:\QC_LEAN\Common\Python\PythonInitializer.cs:line 42 at QuantConnect.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in C:\QC_LEAN\AlgorithmFactory\Loader.cs:line 171 20210417 05:10:50.299 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. The type initializer for 'Delegates' threw an exception. at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC_LEAN\Engine\Setup\ConsoleSetupHandler.cs:line 105 at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath, WorkerThread workerThread) in C:\QC_LEAN\Engine\Engine.cs:line 119
Â
Here is what I've done so far without having any success with resolving this issue:
1. Installed a fresh WINDOWS and removed everything from my computer. SAME ERROR!
2. Installed Visual Studio 2019 and ran LEAN with CSharp config setting, WORKS FINE!
3. Installed latest version of Anaconda and downgraded to python 3.6.8 along with pandas=0.25.3 and wrapt=1.11.2, SAME ERROR!
4. Installed Anaconda3-5.2.0-Windows-x86_64 then upgraded python along with pandas=0.25.3 and wrapt=1.11.2, SAME ERROR!
5. Created a conda environment with python 3.6.8 along with pandas=0.25.3 and wrapt=1.11.2, SAME ERROR!
6. Disable my Anti Virus, SAME ERROR!
I'd really apprciate it, if someone could help me out.
Derek Melchin
Hi Milad,
We recommend using the new CLI as it removes all local install dependence. The installation instructions are available here.
To continue debugging the error above, the error states the system is looking at C:\Anaconda3. Consider checking the path of where anaconda is installed because the default path for anaconda is C:\Users\<your-username>\Anaconda3\.
Best,
Derek Melchin
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.
Yi ren
Hi Milad Resketi.
I got the same error. Have you solved it?
Jalen He
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!