Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)
edited by

I'm trying to follow PEP 328, with the following directory structure:




In I have the following import statement

from ..components.core import GameLoopEvents

However, when I run, I get the following error:

tests$ python

 Traceback (most recent call last):

   File "", line 3, in <module> 

     from ..components.core import GameLoopEvents 

 ValueError:   Attempted relative import in non-package

Is there anything I'm missing here?

1 Answer

0 votes
by (106k points)
  • You need to use the following command like a package which you are not doing while you are running in your CLI:-

pkg/ components/ tests/

  • To get the desired output as you want you to need to use it as a package. And when you are running the command make sure you are outside of directory pkg at the time when you call the package from CLI.

  • If you want to use import components.core  you can use it directly by  appending the current directory to sys.path:

if __name__ == '__main__' and __package__ is None: 

from os import sys, path 


If You want to learn python for data science visit this python course by Intellipaat.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

Browse Categories