Skip to content

Commit dc3fc36

Browse files
authored
[TVMScript] More accurate hints for ImportError (#13662)
1 parent ece99a2 commit dc3fc36

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

python/tvm/script/highlight.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,20 @@ def _get_pygments_style(
160160
if version.parse(pygments.__version__) < version.parse("2.4.0"):
161161
raise ImportError("Required Pygments version >= 2.4.0 but got " + pygments.__version__)
162162
except ImportError as err:
163+
if err.name == "packaging":
164+
name = "packaging"
165+
elif err.name == "pygments":
166+
name = "Pygments>=2.4.0"
167+
else:
168+
raise ValueError(f'Package "{err.name}" should not be used')
169+
163170
with warnings.catch_warnings():
164171
warnings.simplefilter("once", UserWarning)
165-
install_cmd = sys.executable + ' -m pip install "Pygments>=2.4.0" --upgrade --user'
172+
install_cmd = sys.executable + f' -m pip install "{name}" --upgrade --user'
166173
warnings.warn(
167174
str(err)
168175
+ "\n"
169-
+ "To print highlighted TVM script, please install Pygments:\n"
176+
+ f"To print highlighted TVM script, please install {name}:\n"
170177
+ install_cmd,
171178
category=UserWarning,
172179
)

0 commit comments

Comments
 (0)