Hey guys,
I am attempting to run Lean on Ubuntu. I have looked at the other solutions on here but they have not made any difference. The C# code works fine but when I run the Python test Algorithm I get:
I have a Conda environment activated with python 3.6.10 installed.
I am not sure exactly what is going on? Has anyone seen this?
Nicholas Strong
So, I got a little further:
sudo ln -s ~/anaconda3/envs/lean/lib/lib
python3.6m.so /usr/lib/libpython3.6m.so
Now it errors at finding another file.
This does not seem like a good way to do things, though.
Why does Lean look in /usr/lib/ for python and require us to make links there for our files instead of using the conda environment?
Â
Jared Broad
Hello Nicholas, unfortunately we only support 3.6.8. today due to the python integration technology. Please follow this install guide carefully step by step -Â
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/readme.mdÂ
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.
Nicholas Strong
Hi Jared, yes I saw that and switched to Python 3.6.8 and this still persists.
The problem lies in adding links to my /usr/lib directory. This doesn't work well with conda environments (say I have two different environments with python 3.6 then the /usr/lib link will always use the one in the environment I linked it to and doesn't change with environment). Is there a better way to do this?
Jared Broad
Thanks Nick and for the issue. We'll review and see if it's possible to avoid this link in the future. We build the foundation every 2-3 weeks so we will review it in the next build.Â
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.
Brad Hearne
Hey guys, I'm running into this issue as well. I'm have a conda environment with python 3.6.8 on Ubuntu. I tried linking the installations but it broke the system making it where VSCode won't run. I then tried only using the miniconda installation that's in the Github Readme. It again broke the system and VSCode. It looks like the issue lies in linking python as Nicholas is saying. While the linking does allow the QC code to run, it breaks the rest of the system.
I've successfully run Lean implementations on the Windows side with multiple python environments before since you can select the conda environment when Visual Studio builds/runs the C# code. I'm not very familiar with running things on Linux. Is there a similar solution for Linux? Perhaps is there a global variable of sorts that points to the python implementation that can be changed and msbuild re-run to fix it instead using symlinks?
Jasper van Merle
Hi Brad, I've had the same issue as well (Ubuntu 20.04 LTS + Miniconda). What fixed it for me was following the last step in the macOS instructions in the Algorithm.Python/README.md file. This means that I didn't link the file system-wide, but just told Rider (should work with other C# editors too) where to look for the file by writing the following to Launcher/Python.Runtime.dll.config: https://gist.github.com/jmerle/a4e6865e0a833c1405e006a47d7b95e0 (Miniconda is installed to /home/jasper/.miniconda3 and the environment is named "qc" here).
Â
Brad Hearne
Thank you!!! That gets the algorithm running without errors by just updating that file!
One more question, is there a similar fix for the Lean Report module? It gives the same missing dll type error and I see that the .csproj file runs Python from the listed pythonnet rather than a dll.config file like is in the Launcher. I'm even less familiar with implementing anything with pythonnet so I'm not sure if there's a quick fix for that.
Jasper van Merle
I've just tried it and managed to fix the error in the Report project by simply copying over the Python.Runtime.dll.config file from the Launcher project to the Report project, and by making sure matplotlib is installed in the conda environment.
Brad Hearne
Hmmmm, I just tried doing that but the error is still popping up. These are the first couple of lines of the error message:
"Unhandled Exception:
System.DllNotFoundException: python3.6m assembly:<unknown assembly> type:<unknown type> member:(null)
 at (wrapper managed-to-native) Python.Runtime.Runtime.Py_IsInitialized()"
I placed the same Python.Runtime.dll.config file that let the algorithm run in the Report folder. Is there something to do with pythonnet that's needed or is this separate from that?
Â
Â
Jasper van Merle
I can reproduce that error if I copy the file via the file manager instead of via Rider's filetree. What you need to make sure is that the file is registered correctly within the Report project. In Rider you can do that by right-clicking on the Report project, selecting Add and then "Add Existing Item...", after which you need to select the file you copied. I don't know exactly how it works on other editors, but they should have similar functionality.
Jasper van Merle
To add to my previous comment, you also need to configure the file's properties so that it is copied to the output directory.. In Rider this can be done by right-clicking on the file, selecting Properties and setting "Copy to output directory" to "Copy if newer".
Brad Hearne
You are awesome!!! I haven't used Rider before but downloaded it and made the changes you suggested and the behavior carried over to the VSCode implementation that I was using! Thank you for all your help!!!
The details you helped me with should definitely be considered for addition to the Linux Python implementation ReadMe. That's super helpful. I'm assuming the QC guys could update the Github copy with a version that could have a Python.Runtime.dll.config in it from the start without having to use Rider to add it?
Either way, thank you again!
Nicholas Strong
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!