1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Python - Custom package visible but contained functions are not

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    My System/Setup

    • Windows 11 (Enterprise)
    • Running in VS Code
    • Running Python 3.13 in a .venv/
    • Using uv (via python -m pip install uv, I cannot download uv via curl on the system I have to use.)
    The Project Layout


    I have a standard src layout for a Python project with a pyproject.toml file as follows:

    Directory Structure


    my_project/
    ├── .venv/
    ├── img/
    ├── src/
    │ └── lib_name/
    │ ├── __init__.py
    │ ├── lib_name.py
    │ ├── file1.py
    │ └── file2.py
    │
    ├── tests/
    │ ├── __init__.py
    │ ├── test_file1.py
    │ └── test_file2.py
    │
    ├── notebooks/
    │ └── experimental.ipynb
    │
    ├── .gitignore
    ├── .python-version
    ├── README.md
    ├── uv.lock
    └── pyproject.toml

    pyproject.toml:


    [project]
    name = "my_project"
    version = "1.0"
    description = "My cool project."
    readme = "README.md"
    requires-python = ">=3.13"
    dependencies = [
    "numpy>=2.3.2",
    ]

    [dependency-groups]
    dev = [
    "black>=25.1.0",
    "notebook>=7.4.5",
    "pip>=25.2",
    "pytest>=8.4.1",
    "uv>=0.8.14",
    ]

    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"

    [tool.setuptools.packages.find]
    where = ["src"]

    The Problem


    I have already run python -m uv pip install -e . to ensure my project in the src/ directory can be developed in editable mode.

    Then, in my notebooks/, I have a simple .ipynb file that runs import lib_name where I get no errors. I then try to access a function in that imported lib e.g., lib_name.func() Which gives me the following error AttributeError: module 'lib_name' has no attribute 'func'.

    I'm puzzled as to why the notebook can see my module but not the functions contained within it. Running dir(lib_name) in the notebook only gives me the builtin dunder methods where none of my included functions are visible.

    What I've Tried

    • Tweaking the pyproject.toml to ensure that setuptools can see the src/ directory when I run the python -m pip install -e . command
    • Playing around with the contents of the __init__.py files (currently blank) to try to directly import the functions using __all__ to no avail.
    • Implementing solutions from similar questions e.g., this one submitted here.

    I'm unsure if this is related to my project structure, a corrupted .venv/, issues with uv when installed via pip, or perhaps an error in my pyproject.toml file.

    Any advice/support would be greatly appreciated!

    Continue reading...

Compartilhe esta Página