============================= test session starts =============================
collecting ...
test_trade_planning.py:None (test_trade_planning.py)
ImportError while importing test module 'C:\projects\QC\QuantOrganization\TradingAlgoV5C\test_trade_planning.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\..\..\backup\QC\venv\lib\site-packages\_pytest\python.py:493: in importtestmodule
mod = import_path(
..\..\..\backup\QC\venv\lib\site-packages\_pytest\pathlib.py:582: in import_path
importlib.import_module(module_name)
C:\Users\dharm\AppData\Local\Programs\Python\Python310\lib\importlib\__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
???
<frozen importlib._bootstrap>:1027: in _find_and_load
???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:688: in _load_unlocked
???
..\..\..\backup\QC\venv\lib\site-packages\_pytest\assertion\rewrite.py:174: in exec_module
exec(co, module.__dict__)
test_trade_planning.py:5: in <module>
from trade_planning import TradePlanning # Adjust this import based on the actual location of your module
trade_planning.py:1: in <module>
from AlgorithmImports import Resolution
E ImportError: cannot import name 'Resolution' from 'AlgorithmImports' (unknown location)
collected 0 items / 1 error
!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
============================== 1 error in 0.37s ===============================
Process finished with exit code 2
Mia Alissi
The error message indicates that the Python interpreter is unable to import the name 'Resolution' from 'AlgorithmImports'. This could be due to a few reasons:
The 'AlgorithmImports' module is not correctly installed or not available in your Python environment. You need to ensure that this module is installed and accessible in your Python environment.
The 'Resolution' object does not exist in the 'AlgorithmImports' module. You need to ensure that the 'Resolution' object is correctly defined and accessible in the 'AlgorithmImports' module.
The 'AlgorithmImports' module is not in the Python path. You need to ensure that the directory containing the 'AlgorithmImports' module is included in your Python path.
In the context of QuantConnect, the line
from AlgorithmImports import *
is used to import all necessary modules for LEAN to work in Python. This line works only with LEAN installed and compiled locally. If you're using the CLI, you need to run on a docker container in a virtual environment with LEAN (source).If you're running your code outside of the QuantConnect environment, you might need to adjust your imports to correctly reference the modules and objects you're trying to use. If you're running your code in a local setup, you might need to ensure that you have the correct setup for running LEAN locally, as discussed in this forum post.
If you're still having trouble, it would be helpful to know more about your setup. Are you running this code in the QuantConnect environment or in a local setup? What steps have you taken to install and configure LEAN?
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.
Dharmesh Khalasi
I am running this code in a local setup using Pycharm IDE
Mia Alissi
If you're running the code in a local setup using PyCharm, you need to ensure that you have correctly set up LEAN for local development. Here are some steps you can follow:
Make sure you have cloned the LEAN engine from the QuantConnect GitHub repository and built it successfully.
Ensure that your Python environment has access to the necessary QuantConnect libraries. You can add the necessary references in your Python script as follows:
Resolution
object, it should be available after adding the references above. You can use it in your code like this:If you're still facing issues with importing
Resolution
or any other objects, it might be due to the way your project is structured or the way your Python interpreter is set up in PyCharm. Make sure that the Python interpreter in PyCharm is set to the one where you have all the necessary QuantConnect libraries installed.If you're using the LEAN CLI, you need to run your backtests in a Docker container that has access to the LEAN engine. You can find more information on how to do this in the CLI documentation.
Remember, running LEAN locally requires a specific setup and might not work out-of-the-box in a standard Python environment. If you're still having issues, please provide more details about the error messages you're getting and the steps you've taken to set up LEAN locally.
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.
Dharmesh Khalasi
  return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1050: in _gcd_import
  ???
<frozen importlib._bootstrap>:1027: in _find_and_load
  ???
<frozen importlib._bootstrap>:1006: in _find_and_load_unlocked
  ???
<frozen importlib._bootstrap>:688: in _load_unlocked
  ???
..\..\..\backup\QC\venv\lib\site-packages\_pytest\assertion\rewrite.py:174: in exec_module
  exec(co, module.__dict__)
test_trade_planning.py:8: in <module>
  from trade_planning import TradePlanning
trade_planning.py:7: in <module>
  from clr import AddReference
E Â ImportError: cannot import name 'AddReference' from 'clr' (C:\projects\backup\QC\venv\lib\site-packages\clr\__init__.py)
collected 0 items / 1 error
Mia Alissi
The error message indicates that the Python interpreter is unable to import the name 'AddReference' from 'clr'. This is likely because the 'clr' module, which is part of the pythonnet package, is not correctly installed in your Python environment.
Here are some steps you can follow to resolve this issue:
If you have already installed pythonnet, make sure it is the correct version and it is installed in the correct Python environment. If you're using a virtual environment in PyCharm, you need to ensure pythonnet is installed in that virtual environment.
If you're still facing issues, it might be due to a compatibility issue between pythonnet and your Python version. pythonnet supports Python 2.7 and 3.5 onwards, so make sure you're using a compatible Python version.
In the context of QuantConnect, the 'clr' module and 'AddReference' function are used to add references to .NET assemblies, which is necessary for running the LEAN engine. If you're running your code outside of the QuantConnect environment, you might need to adjust your code accordingly.
If you're still having trouble, it would be helpful to know more about your setup. Are you using a virtual environment in PyCharm? What is your Python version? Have you been able to successfully install other packages in your Python environment?
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.
Dharmesh Khalasi
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!