This question already has an answer here:
- Relative imports for the billionth time 9 answers
My project has the following structure:
DSTC/
st/
__init__.py
a.py
g.py
tb.py
dstc.py
Here is a.py
in part:
import inspect
import queue
import threading
Here is tb.py
in part:
import functools
from . import a
When run directly, a.py
produces no errors, and it is easy to verify there were no SyntaxError
s. However, running tb.py
causes the following error:
"C:\Program Files\Python36\python.exe" C:/Users/user/PycharmProjects/DSTC/st/tb.py
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/DSTC/st/tb.py", line 15, in <module>
from . import a
ImportError: cannot import name 'a'
Process finished with exit code 1
How should I rewrite the import of a
from tb
so that tb
can be run directly without causing errors?