Skip to content

Importing module into setup.py can cause ModuleNotFoundError for uninstalled dependencies #3

@maximylius

Description

@maximylius

Hi, first of all thanks for building the tutorial!

When trying to build my first package with it, I ran into a problem which I wanted to report.
In setup.py the line from my_pip_package import __version__ can cause a problem, as it imports part of the package before the package dependencies are installed. For me this lead to a ModuleNotFoundError as I import my package modules into the _init.py_ file and those modules import my dependencies.

To solve this issue I would therefore suggest this solution from stack overflow:

  • in setup.py: remove from my_pip_package import __version__ from and instead sepecify the version number directly setup(..., version="X.X",)
  • in init.py: replace __version__ = 'X.X' with
from importlib import metadata
__version__ = metadata.version('my_pip_package')

No guarantee, that I am right here, but this finally solved my issue after several hours of looking elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions