Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading