I have a project subdivided into packages, in the following structure:
/project
/pkg
__init__.py
engine.y
ai.py
__init__.py
test_script.py
engine.py has an import statement to use ai.py which looks like
import pkg.ai as ai
This means that test_script.py can be run in the command line as python test_script.py
and it has no issues. However for debugging purposes, engine.py is also often run. When running in PyCharm it has no problems but when using python engine.py
I get errors saying No module named pkg
.
Is there any way I can run engine.py in the command line so that it does not have import errors the way PyCharm does it?
Interestingly the way PyCharm works is that if I do not put that pkg.
in front of the import module, it underlines it in red saying it can't find the module (but still runs). I've looked everywhere for a solution to this but have only got more confused.