Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
maximylius opened this issue Oct 28, 2024 · 0 comments

Comments

@maximylius
Copy link

maximylius commented Oct 28, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant