Trouble importing from my own package

Hi, I am following the steps you showed above but things are still not working. this is what I’m doing: I create a virtual environment called ‘.venv’, then make my own package with the structure you have shown above. the package is importable, and the functions inside the package could be read by pylance, but I cannot use those function from anywhere.

this is my project structure:

-.venv
-package
    -my_utils
        -__init__.py
        -image.py
    -pyproject.toml
-main.py

I then went to root/package and pip install -e .
This error displays when I tried to call the function:

ImportError: cannot import name 'show_image' from 'my_utils.image' (/home/bao/archive/package/my_utils/image.py)'''

Any idea how to fix this?

What does your pyproject.toml look like? What does __init__.py contain?

With a project structure identical to yours, and the following pyproject.toml, __init__.py, and image.py files:

# pyproject.toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "my_utils"
description = "description goes here"
version = "0.1.0"
# __init__.py
from .image import show_image
# image.py
def show_image():
    print("IMAGE!")

I can import show_image after pip install -e .:

$ pwd
~/tmp/archive/package
$ pip install -qe .
$ cd ..
$ python -c "from my_utils import show_image; show_image()"
IMAGE!