0

this is my file system: source: |_ folder1: myfile.py |_ folder2: infile.py

I am currently working with "infile.py" and I want to import myfile.py from folder1, doing the following:

from ..folder1.myfile import *

result: ImportError: attempted relative import with no known parent package

in my file I don't have any class, only functions, so I don't know if it is necessary to create a class in order to import a file as a module in Python.

  • i think discussion in [link](https://iq-inc.com/importerror-attempted-relative-import/) likely should help aluminate what is likely going on. to your questions about needing classes/functions/etc, that shouldnt be issue, there is not such requirement for python imports – kamster Feb 06 '22 at 03:30
  • I think all the information you need can be found here, https://stackoverflow.com/questions/15208615/using-pth-files. You can use the .pth method mentioned or just append the path to the sys.path list. –  Feb 06 '22 at 03:46
  • Is the word "dile" in the title a typo and meant to be a "file"? – Stefan Wuebbe Feb 16 '22 at 18:01

0 Answers0