1

I am creating a python package which follows the structure:

project
├── package
│   ├── __init__.py
│   ├── __main__.py
│   └── subpackage01
│       ├── functions01.py
│       ├── __init.py__
│       └── subpackage02
│           ├── functions02.py
│           ├── __init__.py
├── requirements.txt
├── setup.py

In __main__.py I have from .subpackage01.functions01 import foo which gives me the error ImportError: attempted relative import with no known parent package.

If I remove the dot before subpackage01 it works but stops working in my pypi package. Removing the dot, building the package and uploading it gives me the error ModuleNotFoundError: No module named 'subpackage01'.

I can't understand the why, since in functions01.py I have relative imports for subpackage02 that works with no problem. Also I can't figure out why it works when the package is built and doesn't in a local development environment.

Vitor Falcão
  • 1,007
  • 1
  • 7
  • 18

1 Answers1

1

Try from subpackage01.functions01 import foo it's a subtle difference by removing the leading dot from subpackage01.

slayer
  • 643
  • 7
  • 14