0

One usually gets the pandas version in Python as follows:

import pandas
print(pandas.__version__)

However if numpy version 2.0.0 or higher is installed, and the pandas version is < 2.2.2 it typically crashes as follows on the import statement:

enter image description here

Is there a clever way to check the pandas version (within Python) in order to warn the user of this incompatibility instead of the user-unfriendly traceback dump?

3
  • You could use a try: ... except ValueError: ... to catch the error pandas is throwing. Commented Sep 25, 2024 at 17:52
  • Okay, I can trap it that way but I would also like the pandas version number within the message. Commented Sep 25, 2024 at 18:04
  • You can get a package's version without importing it using importlib: stackoverflow.com/questions/3524168/… Commented Sep 25, 2024 at 18:11

1 Answer 1

0

You can use try except block to catch the error and return. Sample code is as follows:

try:
    import pandas as pd
except ValueError as e:
    print(f"Import error: {e}")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.