Hi,
I'm working with Visual Studio + Python to develop my algorithm locally. I follow these instructions to debug. When I start debugging (after setting at least one breakpoint), I am met with the following error:
Exception has occurred: NameError
name 'AlphaModel' is not defined
This code runs fine in the cloud. Autocomplete (via quantconnect-stub) works fine in my instance of VS. All files have
from AlgorithmImports import *
In them.
Can someone tell me what I'm doing wrong? Thanks.
Mia Alissi
Here's a troubleshooting checklist you can follow if you encounter the error "NameError: name 'AlphaModel' is not defined" while developing locally with Visual Studio and quantconnect-stubs, even though the code works fine in the cloud:
TROUBLESHOOTING CHECKLIST: NameError: name 'AlphaModel' is not defined
Confirm 'AlgorithmImports.py' Re-exports AlphaModel
AlgorithmImports.py
file provided by quantconnect-stubs (or your local copy).__all__
statement. Example:Verify quantconnect-stubs Installation
Check Python Interpreter Selection
Try Manual Import to Pinpoint Issue
Check/Update quantconnect-stubs
Restart Visual Studio/VS Code
Double-check Usage
AlphaModel
that could cause shadowing.Test With Minimal Script
Be Aware of Cloud vs. Local Differences
Seek Further Help if Needed
Usually, manually importing
AlphaModel
or updating your AlgorithmImports file solves this. Restart your IDE after making changes!Let me know if you need help with any of the steps.
Sources: Autocomplete - QuantConnect.com, Debugging - QuantConnect.com
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.
Paul R
Output of
and on and on..
I tried
already, and while it makes this issue go away, another pops up:
So I figured it's something with my local environment, I just don't know what. I googled around and it says to import “pythonnet” to make this new error go away. Problem is, I already have pythonnet in my path.
I tried your “test.py” suggestion.
Again, new error is:
pythonnet already imported.
Paul R
The latest issue is now:
This seems to stem from some sort of compatibility issues between .NET and Python on Apple Silicon Macs using VS.
From QuantConnect package __init__.py:
I have no idea how to rectify this or what is going on. Perhaps some naming collision with “clr” that breaks this code, but its unable to find QuantConnect.Common as a result. Obviously this breaks the whole debugging process for me.
Any help would be greatly appreciated.
Paul R
You can close the ticket. The issue is that you can't actually locally debug a QuantConnect cloud project.
Paul R
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!