2

This question should be relatively quick and easy. I just am trying to find out which version of Python's math and cmath packages I have.

Unfortunately, I did not install them using pip. I have already reviewed this stack article which was helpful (because I did not know pip freeze before). However, both packages are not on the list.

I've tried google and looking around a bit, but to no avail. I have tried the following in the interpreter:

import math
print math.__version # error
print math.version # error

I have also tried to use python's help command and breeze through the documentation, but once again, couldn't find anything about how to detect which version I have installed.

I'm not exactly sure what else to try. Any thoughts? Thanks again for your time!

Community
  • 1
  • 1
jlarks32
  • 931
  • 8
  • 20

2 Answers2

4

You can't. Neither math or cmath carry any specific version. They're related to the Python version you're using.


If it's because you want to check whether a function is present or not, let's say isfinite which was added in 3.2. Then you could do that using hasattr:

print(hasattr(math, "isfinite"))

or using sys.version_info:

has_infinite = sys.version_info >= (3, 2)
print(has_infinite)

Both prints True since I'm using Python 3.6.

vallentin
  • 23,478
  • 6
  • 59
  • 81
1

Absolutely agree with @Vallentin

If you want to know available attribute or methods you could use dir() function. dir() is a powerful inbuilt function in Python 3, which returns list of the attributes and methods of any object (say functions , modules, strings, lists, dictionaries etc.)

import math
print(dir(math))

It will returns a list of available attributes and methods from math packages.

YGautomo
  • 619
  • 8
  • 12