[Python] Mediapipe Hands module resolves incorrect path to .task file

Discussão em 'Python' iniciado por Stack, Julho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am following the documentation, but BaseOptions seems to resolve the model path incorrectly — instead of using my project directory, it prepends a Python package path.

    base_options = BaseOptions(model_asset_path='hand_landmarker.task')
    options = HandLandmarkerOptions(
    base_options=base_options,
    running_mode=VisionRunningMode.IMAGE,
    num_hands=2
    )


    This results in an invalid path like:

    C:\Users\User\AppData\Roaming\Python\Python310\site-packages/C:\Users\User\source\repos\JFLewelery_Bot_AI\hand_landmarker.task
    Errno 22


    Why is the path prefixed with site-packages/, and how can I prevent that? The face/pose models work fine in the same setup.

    I also tried using pathlib, but it didn’t help:

    task_path = Path(__file__).resolve().parents[2] / "hand_landmarker.task"
    if not task_path.exists():
    raise FileNotFoundError(f"Model file not found at: {task_path}")

    options = HandLandmarkerOptions(
    base_options=BaseOptions(model_asset_path=str(task_path)),
    running_mode=VisionRunningMode.IMAGE,
    num_hands=2
    )

    Continue reading...

Compartilhe esta Página