Skip to content

Conversation

@moratom
Copy link
Collaborator

@moratom moratom commented Mar 5, 2024

No description provided.

@moratom moratom requested a review from SzabolcsGergely March 5, 2024 17:04
try:
import open3d as o3d
except ImportError:
print("Open3D not installed, to be able to run the example install Open3D with: python3 -m pip install open3d")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather use sys.executable instead python3.
Also raise instead exit, or raise a new exception with this message

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import sys

try:
    import open3d as o3d
except ImportError:
    sys.exit("Critical dependency missing: Open3D. Please install it using the command: '{} -m pip install open3d' and then rerun the script.".format(sys.executable))

Copy link
Collaborator Author

@moratom moratom Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on sys.executable.

Why raise instead of an print and an exit though? If we catch exactly what the error is - isn't it cleaner to output a clean "what to do" message than what's the output of an uncatched error:

matevz@matevz-luxmmPC:~/Luxonis/Depthai/depthai-python/examples/PointCloud$ python visualize_pointcloud.py 
Open3D not installed, to be able to run the example install Open3D with: /usr/bin/python -m pip install open3d
Traceback (most recent call last):
  File "visualize_pointcloud.py", line 8, in <module>
    import open3d as o3d
ModuleNotFoundError: No module named 'open3d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "visualize_pointcloud.py", line 12, in <module>
    raise ImportError(errorMessage)
ImportError: Open3D not installed, to be able to run the example install Open3D with: /usr/bin/python -m pip install open3d

EDIT: I didn't see the second comment, agree with the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, use sys.exit("message") imo

@moratom moratom merged commit a2e419e into develop Mar 5, 2024
@moratom moratom deleted the improve_pointcloud_example branch March 5, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants