Search code examples
pythonpython-packaging

Why can I only use my package with "from" import?


When installing my package in editable mode (pip install -e .), I can only use it's functions using an import with from:

from package import hello_world

hello_world.hello_world()

using only import doesn't work:

import package

package.hello_world.hello_world()

This results in NameError: name 'hello_world' is not defined

Is there something I need to set up in my package, so that I can just import the package?


Solution

  • In file package/__init__.py you have to use from . import hello_world


    At this moment you can only do import package.hello_world