Back

(Python) Libraries and directories

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?

Update Backtest








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. 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed