Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ImportError
#1
I have a directory structure as below:
WD/
main.py
pkg1/
__init__.py
file1.py
file2.py

Now I would like to import pkg1 in my main python code "main.py". I use the following and it works OK
import pkg1
but if I use, the following, i am getting an ImportError
from . import pkg1
ImportError: cannot import name 'pkg1' from '__main__' (main.py)

On the other hand, I don't get an error if I use the same syntax for importing a module
For example, if I use the following in __init__.py file
from . import file1.py
Reply


Messages In This Thread
ImportError - by fullstop - Dec-13-2019, 05:22 AM
RE: ImportError - by Gribouillis - Dec-14-2019, 04:50 PM
RE: ImportError - by fullstop - Dec-15-2019, 02:04 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020