Python SDK error when importing labelbox.types

Hi,

I’m trying to follow this guide to import text annotations using the Python SDK but I’m getting the following error when executing import labelbox.types as lb_types:

Traceback (most recent call last):
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/types.py", line 2, in <module>
    from labelbox.data.annotation_types import *
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/__init__.py", line 1, in <module>
    from .geometry import Line
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/geometry/__init__.py", line 1, in <module>
    from .line import Line
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/geometry/line.py", line 3, in <module>
    import geojson
ModuleNotFoundError: No module named 'geojson'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/types.py", line 4, in <module>
    raise ImportError(
ImportError: There are missing dependencies for `labelbox.types`, use `pip install labelbox[data] --upgrade` to install missing dependencies.

After executing pip install labelbox[data] --upgrade, I then get a different error:

Traceback (most recent call last):
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/types.py", line 2, in <module>
    from labelbox.data.annotation_types import *
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/__init__.py", line 1, in <module>
    from .geometry import Line
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/geometry/__init__.py", line 1, in <module>
    from .line import Line
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/data/annotation_types/geometry/line.py", line 5, in <module>
    import cv2
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/ml-automarking-modelbuild/.venv/lib/python3.9/site-packages/labelbox/types.py", line 4, in <module>
    raise ImportError(
ImportError: There are missing dependencies for `labelbox.types`, use `pip install labelbox[data] --upgrade` to install missing dependencies.

I’m using a GitHub codespace and the following Python 3.9.17 docker image mcr.microsoft.com/devcontainers/python:3.9 and developing within a virtual env with no packages installed other than labelbox

Hi @tw974 ,

Labelbox uses a few dependencies : https://github.com/Labelbox/labelbox-python/blob/develop/requirements.txt

I would recommend you to install labelbox[data] instead to make sure you have all dependencies installed.

pip install "labelbox[data]"

refer to : labelbox · PyPI

Many thanks,
PT
Labelbox Support

Thanks for your reply @ptancre, I have tried to install labelbox[data] directly in a fresh environment but still get the same error…

weird, I have provided the requirement list (https://github.com/Labelbox/labelbox-python/blob/develop/requirements.txt), I guess you can pass them in your env and this will sort your issue.

The error is due to opencv-python not being properly installed.

A solution for me was to manually install the missing dependency libgl1 inside my codespace docker container following this:

Now it works fine. Thanks for your support

1 Like

Thank you for the follow up!

Many thanks,
PT
Labelbox Support