I created and uploaded a python library It works if I add all files at the root level, eg:
/bar.py
And then use it in my algorithm's main.py:
from bar import Market
But it does not work if I add the library in a subdirectory, eg:
/foo/__init__.py
/foo/bar.py
And then use it in my algorithm's main.py:
from foo.bar import Market
Which causes the error:
Build Error: File: main.py Line:1 Column:0 - ModuleNotFoundError: No module named 'foo'
How can my algorithms access directories in my modules/libraries?
Jared Broad
Libraries is the wrong name for the feature, we're going to update the GUI and make it more obvious. You can think of it more like "project references" or even "external files". The system was built to handle multiple files but I'm not sure it'll handle a full python library setup yet.
"Libraries" was meant to allow people to import Algorithm Framework modules; so you can import modules from other projects without needing to copy-paste the code.
Gustavo's actively working on this in beta so give us another few days and the "external projects" will be more apparent.
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.
Hussain
What's the latest on this?
It appears to still be the case today that Python projects can only have one file and it must be named main.py.
I couldn't find anything in Docs about "Libraries".
Is the "Libraries" feature useable?
Shile Wen
Hi Hussain,
Users can have multiple .py files and import functions/classes as we normally do in Python. Please see this algorithm for an example of using multiple .py files.
Best,
Shile Wen
Joao Antunes
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!