Skip to content

Suggestion for disambiguation re import expectations and __init__.py #1929

Open

Description

@malcolm-heath

Issue Description

Having just gone through the tutorial, I found myself confused because once the project is packaged and installed, and then imported, the add_one() function seemed unavailable.

  • "import example_package" was without error, but attempting to use example_package.add_one(3) gave AttributeError: module 'example_package' has no attribute 'add_one'

  • "from example_package import add_one" gives ImportError: cannot import name 'add_one' from 'example_package'

  • "from example_package import *" runs without error, but then attempting to use add_one gives NameError: name 'add_one' is not defined

The only way I have been able to run "add_one()" has been as
"from example_package.example import add_one".

While this is understandable as the function is defined in the top level example.py file, it definitely violated my expectations as almost every package I use would allow me to use "import example_package" and then "example_package.add_one()" or "from example_package import add_one" and then run "add_one()"

I am suggesting either an example of loading the package and using the function, or the addition of modifying the init.py to add "from .example import add_one"

Code of Conduct

  • I am aware that participants in this repository must follow the PSF Code of Conduct.

Activity

  1. ncoghlan commented on Oct 10, 2025

    @ncoghlan
    Member

    There is a short usage example at the end of https://packaging.python.org/en/latest/tutorials/packaging-projects/#installing-your-newly-uploaded-package, but that could perhaps be made clearer with a dedicated "Using your newly installed package" heading.

  2. Herrtian commented on May 22, 2026

    @Herrtian
    Contributor

    This still looks actionable as a small tutorial docs change: add a "Using your newly installed package" heading after installing from TestPyPI/PyPI and make the existing import example easier to find.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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