0

I have seen many questions and answers for this same, but none of them solved mine. Please have a look into this,

This is my folder structure,

code/ 
  helloworld.py
stdlib/
  stdio.py
  stddraw.py 
  __init__.py

Inside __init.py i have done

from . import stdio

Inside helloworld.py, i have done

from ..stdlib import stdio
stdio.writeln("Test")

But it says me an error saying, "attempted relative import with no known parent package" Can anyone please explain me what i am doing wrong in this case?

nano
  • 17
  • 1
  • 5
  • 1
    This question [(Importing files from different folder)](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) might be what you're looking for. – Have a nice day Feb 23 '21 at 03:59
  • as @wangonya suggested, you should make a parent package and add a __init__.py file. After that you should import like this: ```from stdlib import *``` – Anjaan Feb 23 '21 at 04:06

1 Answers1

0

As the error says, you would need a "parent package" for what you're currently doing to work. Something like this:

parent/
 __init__.py
 code/ 
  helloworld.py
 stdlib/
  stdio.py
  stddraw.py 
  __init__.py
wangonya
  • 42
  • 3
  • 9