How do I check the versions of Python modules?
To retrieve the version of a Python module, you can use the __version__
attribute directly in your Python code or run the pip show
command in your command-line interface.
These two methods swiftly get you the installed version of the Python module you're looking into.
Miscellaneous ways to check version details
There are plenty of ways to probe the version details of Python packages and modules. Here, we'll explore them at the command line level to Python's built-in facilities.
Communicating with Python from the terminal
Whether it's Linux, MacOS, or Windows, your command-line interface has got you covered:
- On Linux/Mac:
- On Windows:
Digging deeper into Python
Sometimes, you've got to go deeper:
And starting Python 3.8, you can even go meta:
Harnessing the power of virtual environments
For project isolation, use tools such as virtualenvwrapper
:
From easy_install to pip: an evolution story
Transitioning from easy_install
to pip
is like upgrading from a bicycle to a sports car. With pip
, you unlock commands like:
Remember to be precise with package names, as the exact name you input should correspond to the PyPI listing.
What if there is no __version__
?
Some modules got attitude, they don't have a __version__
:
Plugging into importlib metadata
As Python development evolves, the importlib metadata library is becoming the new norm for retrieving package versions:
Using virtual environments for peace of mind
Virtual environments back up your project environment. This way, you can replicate environments with ease using requirements.txt
files generated by pip freeze
.
Was this article helpful?