-1

This is a test directory.

Main_folder
|-- in_root.py
|-- 1stlayer
   |-- 1stlayer.py

So I want to import some functions from in_root.py in 1stlayer.py. I tried from ..in_root import * but it gave me the error, 'attempted relative import with no known parent package'. Please anyone help, I am always stuck with higher level relative imports in my projects.

Krish Garg
  • 73
  • 2
  • 6
  • 2
    Does this answer your question? [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time) – mkrieger1 Jun 21 '21 at 14:09

1 Answers1

-1

This link is might be the one you are looking for!

Also PYTHONPATH might be helpful! It is an enviromental variable which can contain the directory where your script is.

PYTHONPATH = PATH/libs/

  • libs | lib.py
  • project | project.py

from project.py:

import lib.py

A brief explanation: https://bic-berkeley.github.io/psych-214-fall-2016/using_pythonpath.html

Wrench56
  • 290
  • 2
  • 14