How to avoid 'from module import module' when creating a pypi package?

Viewed 78

I created a pypi package, and I want to be able to do this:

from module import function

But it seems i can only access the function if I do:

from module import module
module.function()

My folder structure looks like this:

modulename (folder)
-- setup.py (Setup python file)
-- modulename (folder)
---- modulename.py (Python file with code in it)
---- __init__.py (Empty python file)
1 Answers

If the "packages" and "package_dir" are not supposed to change, you may try to add import statement in (root)/modulename/modulename/__init__.py.

from .modulename import function
Related