0

There is folder with 2 documnet - __init__.py and main.py.

Code in __init__.py:

a = 1

Code in main.py:

from . import a

print(a)

When I try to run main.py, the terminal displayed:

Traceback (most recent call last):
  File "[myfolder]/main.py", line 1, in <module>
    from . import a
ImportError: cannot import name 'a'
Leon
  • 1
  • 2
    How exactly do you attempt to run main.py? What is the current working directory, and what command do you use? – Karl Knechtel Jan 20 '22 at 09:42
  • I used `C:/Users/[myusername]/AppData/Local/Programs/Python/Python36/python.exe [myfolder]/main.py` in PowerShell – Leon Jan 20 '22 at 09:47
  • What about `from myfolder import a`? – Expurple Jan 20 '22 at 12:37
  • I can't reproduce this. When I try, I instead get [a different issue that I completely expected](https://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py); and when I apply the answer shown there (which I was also completely familiar with) it works properly. Although maybe 3.6 reported the problem this way? – Karl Knechtel Jan 20 '22 at 14:44

0 Answers0