0
folder0
 | __init__.py
 | folder1
 |  | __init__.py
 |  | folder2
 |  |  | __init__.py
 |  |  | script.py
 | folder3
 |  | __init__.py
 |  | module.py

How to import module.py in script.py? I tried having from ...folder3 import module in script.py and running python script.py in folder2 gives me ImportError: attempted relative import with no known parent package. I am using Python 3.7. I have spent many hours reading many posts on the topic and it is still not working. Please help.

Lei
  • 733
  • 1
  • 5
  • 13
  • Specifically, [this answer](https://stackoverflow.com/a/28154841/). Solution 3 is recommended, you should set your project up as a Python package. – metatoaster Mar 17 '23 at 02:06
  • Thanks! A quick question on your last point: Have I already set it as a Python package by having an `__init__.py` under every folder? – Lei Mar 17 '23 at 02:14
  • 1
    No, `__init__.py` used to define a namespace in Python 2, and has been deprecated for this usage in Python 3. You will need to create either a [`setup.py` using `setuptools`](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/) (additionally, [namespace packages](https://packaging.python.org/en/latest/guides/packaging-namespace-packages/)) or using other compatible methods (such as [`pyproject.toml`](https://packaging.python.org/en/latest/tutorials/packaging-projects/)). – metatoaster Mar 17 '23 at 02:18

0 Answers0