Hi,
I have tried succesfully to build and run a C# strategy. But when compiling (No errors) and running a Python Strategy QuantConnect.Lean.Launcher.exe exist with code error 1.
I think I have done all the steps indicated in github page but I miss something maybe.
My config is: VS2017 Community + Anaconda + python2.7 with panda package added (I put some capture . Any idea please??
Thanks
LukeI
I couldn't get python working on desktop lean either, It wouldn't recognize that I had python2.7 installedbut I followed all the directions I could find. I wonder if they could do a quick video showing how to start from scratch and run a python backtest on desktop lean like the video they have for C#
Jared Broad
Can you please paste the an error message? From the screen shots I am guessing its because you have installed anaconda-python; I think it needs plain python?
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.
Alexandre Catarino
Could you please give us more details?
What is the runtime error message?
made a related question today:
LukeI
I think I found my problem, I haven't figured out how to fix it yet, although I'm close. I keep getting this message:
I figured out that I didn't follow the python readme.md as close as I thought. First I created a system path variable to my python 2.7 install location because I had forgotten to do that. Then I read this instruction closer:
Rename `Lean\packages\QuantConnect.pythonnet._version_\build\Python.Runtime.win` to `Lean\packages\QuantConnect.pythonnet._version_\lib\Python.Runtime.dll`. I didn't realise that by rename it also meant that I had to move it to the lib folder. Then I made sure that python was working in visual studio by reading some stuff here and making python 2.7 the default python environment. I tested the python interactive prompt in visual studio to confirm that it worked.
THEN I redownloaded and used a fresh version of lean. Still got the error.
Now I did a little more digging into what I think is the true cause:
Unable to find an entry point named 'PyUnicodeUCS4_FromUnicode' in DLL 'python27'.
I just checked and my python is UCS-2. I just installed it from the python website so I had no idea that I had to specify for it to install encoded a certain way. But I'm going to try and resintall python 2.7with --enable-unicode=ucs4 somewhow and see if that works. I will report back later.
LukeI
Hmm nope, can't get it
Jared Broad
and the windows dll is needed for it. Alex will reply in a few hours when
he's awake =)
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.
LukeI
OK so I got it working. I uninstalled everything, including visual studio and python and reinstalled it. I also made SURE to copy over the .dll to the right spot and deleted the DLL that was there initially. Part of the reason I think it was giving me problems was because I am on 64bit windows and I had installed multiple versions of python installed, for both 64bit and 32bit. This time I let Visual basic install python 2.7 64 bit during the installation instead of doing it myself. It installed it to a folder at C:\Python27amd64. I had to point the path in my system to C:\Python27amd64, not C:\Python27 like the readme says (which is the 32bit version by default).
Chris Alteras
Hi ,
thanks you everybody for your help.
logs and screenshot : https://groups.google.com/forum/#!topic/lean-engine/mQeSrNsZ6
My install: python integration option checked during VS2017 community installation.
I didn't install python 2.7 in first intention because ananconda was already install and managing packages is very easy (pandas and dependencies in one click!)
PS: I have also an another problem with environment": "backtesting-desktop" that I have fixed.
https://groups.google.com/forum/#!topic/lean-engine/vnE-tXRMKo0
Chris Alteras
I haven't tested my python2.7 anaconda environnement VS integration (https://docs.microsoft.com/en-us/visualstudio/python/python-environments)... It could be the problem
Alexandre Catarino
I am glad you made it.
Like Jared said, that runtime error tells us that you were using the wrong dll (unfortunatelly we need a dll for each OS).
Jared Broad
Chris Alteras a user in the slack channel manage to get it working with Anacondas:
But i've managed to work around it  by installing pythonnet : * brew install pkg-config * brew install glib --universal * brew install mono * export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/5.2.0/lib/pkgconfig * cd /Users/sl624/anaconda/lib * ln -s /Library/Frameworks/Mono.framework/Versions/Current/lib/mono * export DYLD_LIBRARY_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib * USE_OSX_FRAMEWORKS=0 ARCHFLAGS="-arch x86_64" pip install git+https://github.com/pythonnet/pythonnet
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.
Chris Alteras
Jared: slack channel infos are for linux user (mono install and linux command like ln -s ...)
finally I did it.
My steps:
- install python x64
(don't forget path add option )
- open console (cmd) and install panda: py -2.7 -m pip install pandas
- download lean from github
- open with VS2017 , select solution, click right and select restore nuget package
- open python environment and select Python2.7 x64 (maybe not mandatory)
- follow github instruction carefully( rename .win to .dll and paste in lib folder , etc...)
- run ...
- If you want GUI: * click solution, properties, project dependencies and click on Quanconnect.Views
* in config.json : "environment": "backtesting-desktop"
* AND replace in config.json ..../Debug/QuantConnect.Views.exe by .../Release/QuantConnect.Views.exe
you should have:
"desktop-http-port": "1234",
"desktop-exe": "../../../UserInterface/bin/Release/QuantConnect.Views.exe"
- don't forget user id ( see quantconnect , MyAccount)
Lucas
Hi Guys, After reading all above I still cant get it. Could anyone provide some info on what I am doing wrong here? The following text is coming up red when i run the lean launcher
20170904 13:11:35 Error:: Loader.TryCreatePythonAlgorithm(): System.DllNotFoundException: Unable to load DLL 'python27': 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.AlgorithmFactory.Loader.TryCreatePythonAlgorithm(String assemblyPath, IAlgorithm& algorithmInstance, String& errorMessage) in C:\QC_lean\Lean-master\AlgorithmFactory\Loader.cs:line 164
20170904 13:11:36 Error:: Engine.Run(): System.Exception: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. Unable to load DLL 'python27': The specified module could not be found. (Exception from HRESULT: 0x8007007E): try re-building algorithm.
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 94
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Engine.cs:line 111
Chris Alteras
Lucas: check in c:\python27 if you have python27.dll
If not try to copy C:\Windows\System32\ python27.dll (or C:\Windows\SysWOW64) into c:\python27
Lucas
Chris you are a champion. That fixed that problem, cheers!
Now I am up to the error (this pops up in the gui, but there is red in the cmd too)
2017-09-05T07:27:12.1211034Z Error Algorithm.Initialize() Error: Loader.TryCreatePythonAlgorithm(): Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B): try re-building algorithm. Stack Trace: at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 94
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Engine.cs:line 111
at QuantConnect.Lean.Engine.Setup.ConsoleSetupHandler.CreateAlgorithmInstance(AlgorithmNodePacket algorithmNodePacket, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Setup\ConsoleSetupHandler.cs:line 94
at QuantConnect.Lean.Engine.Engine.Run(AlgorithmNodePacket job, AlgorithmManager manager, String assemblyPath) in C:\QC_lean\Lean-master\Engine\Engine.cs:line 111
The first few lines in my config.json looks like:
"environment": "backtesting-desktop",// "live-paper", "backtesting", "live-interactive", "live-interactive-iqfeed"
// algorithm class selector
"algorithm-type-name": "BasicTemplateAlgorithm",
// Algorithm language selector - options CSharp, FSharp, VisualBasic, Python, Java
//"algorithm-language": "CSharp",
"algorithm-language": "Python",
//Physical DLL location
//"algorithm-location": "QuantConnect.Algorithm.CSharp.dll",
"algorithm-location": "../../../Algorithm.Python/BasicTemplateAlgorithm.py",
//"algorithm-location": "QuantConnect.Algorithm.FSharp.dll",
//"algorithm-location": "QuantConnect.Algorithm.VisualBasic.dll",
//"algorithm-location": "QuantConnect.Algorithm.Java.dll",
Chris Alteras
sorry lucas, i was quite busy these day.
step1:check project depencies: select solution level, click right, select properties
check if Views is included
step2: correct Debug with Release in config.json (read carefully my previous post)
Lucas
Hi Chris, Thanks for getting back to me.
I started on a fresh pc. Running win 10 with MSVS 2017 community and python x64 2.7 that comes preinstalled with visual studio. I am still failing dismally.
The error is the same as the original post: Unable to import python module ../../../Algorithm.Python/BasicTemplateAlgorithm.py. Unable to find an entry point named 'PyUnicodeUCS4_FromUnicode' in DLL 'python27'.
Attached is a screenshot of my path location
You mentioned python.dll in syswow or system32. I have one python.dll in each (not sure if that even matters, I have tried C:\Python27amd64\python.dll (with both and with none, I still get the same error)
Jared Broad
Lucas that error probably means you've copied the wrong DLL in place. UCS2 is the mac/linux version of the DLL -- UCS4 is the window one which it needs too work. I guess you didn't *precisely* copy the file: (note the paths)
Rename Lean\packages\QuantConnect.pythonnet._version_\build\Python.Runtime.win to Lean\packages\QuantConnect.pythonnet._version_\lib\Python.Runtime.dll
The version is 1.0.4.4 at the moment:
del Lean\packages\QuantConnect.pythonnet.1.0.4.4\lib\Python.Runtime.dll copy Lean\packages\QuantConnect.pythonnet.1.0.4.4\build\Python.Runtime.win Lean\packages\QuantConnect.pythonnet.1.0.4.4\lib\Python.Runtime.dll
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.
Lucas
I am pretty sure I have done that part correctly (I have read the instructions and attempted about 10 installs now).
Maybe I am not installing python properly?
.
Jared Broad
Sorry Lucas Alex tells me he can't get it going on Windows either (fine on Mac/Linux). We'll figure it out it today and update the install readme.
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.
Chris Alteras
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!