![]() |
|
[Tut] How to Check ‘abc’ Package Version in Python? - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] How to Check ‘abc’ Package Version in Python? (/thread-99723.html) |
[Tut] How to Check ‘abc’ Package Version in Python? - xSicKxBot - 07-20-2022 How to Check ‘abc’ Package Version in Python? 5/5 – (2 votes) In this article, I’ll show you: How to check the version of the Python module (package, library) Code: abcCode: abcThese are the eight best ways to check the installed version of the Python module Code: abc
Before we go into these ways to check your Code: abcA Note on Python Version Numbering Python versioning adds a unique identifier to different package versions using semantic versioning. Semantic versioning consists of three numerical units of versioning information in the format Code: major.minor.patch![]() In this tutorial, we’ll use the shorthand general version abbreviation like so: Code: x.y.zPractical examples would use numerical values for Code: xCode: yCode: z
This is shorthand for Code: major.minor.patch
Let’s dive into the meat of this article: Question: How to check the (major, minor, patch) version of Code: abcMethod 1: pip show To check which version of the Python library Code: abcCode: pip show abcCode: pip3 show abcThis will work if your pip installation is version 1.3 or higher—which is likely to hold in your case because pip 1.3 was released a decade ago in 2013!! Here’s an example in my Windows Powershell: I’ve highlighted the line that shows that my package version is Code: a.b.cCode: PS C:\Users\xcent> pip show abc
Name: abc
Version: a.b.c
Summary: ...
Home-page: ...
Author: ...
Author-email: ...
License: ...
Location: ...
Requires: ...
Required-by: ...In some instances, this will not work—depending on your environment. In this case, try those commands before giving up: Code: python -m pip show abc
python3 -m pip show abc
py -m pip show abc
pip3 show abcNext, we’ll dive into more ways to check your Code: abc![]() But before we move on, I’m excited to present you my new Python book Python One-Liners (Amazon Link). If you like one-liners, you’ll LOVE the book. It’ll teach you everything there is to know about a single line of Python code. But it’s also an introduction to computer science, data science, machine learning, and algorithms. The universe in a single line of Python! ![]() The book was released in 2020 with the world-class programming book publisher NoStarch Press (San Francisco). Link: https://nostarch.com/pythononeliners Method 2: pip list To check the versions of all installed packages, use Code: pip listCode: abcThis will work if your pip installation is version 1.3 or higher. Here’s a simplified example for Windows Powershell, I’ve highlighted the line that shows the package version is Code: 1.2.3Code: PS C:\Users\xcent> pip list
Package Version
--------------- ---------
aaa 1.2.3
...
abc 1.2.3
...
zzz 1.2.3In some instances, this will not work—depending on your environment. Then try those commands before giving up: Code: python -m pip list
python3 -m pip list
py -m pip list
pip3 listTo check the versions of a single package on Windows, you can chain Code: pip listCode: findstr abcCode: pip3 list | findstr abcCode: abcHere’s an example for Code: abcCode: pip3 list | findstr abc 1.2.3To check which version is installed of a given Code: libraryCode: library.__version__Code: import libraryHere’s the code: Code: import my_library
print(my_library.__version__)
# x.y.z for your version outputHere’s an excerpt from the PEP 8 docs mentioning the Code: __version__“PEP 8 describes the use of a module attribute called Code: __version__Code: __version__You can also use the following one-liner snippet to run this from your terminal (macOS, Linux, Ubuntu) or CMD/Powershell (Windows): Code: python3 -c "import my_library; print(my_library.__version__)"However, this method doesn’t work for all libraries, so while simple, I don’t recommend it as a general approach for that reason. Method 5: importlib.metadata.version The Code: importlib.metadataCode: importlib.metadata.version('abc')Code: abcCode: 1.2.3Here’s the code: Code: import importlib.metadata
print(importlib.metadata.version('abc'))
# 1.2.3If you have created your Python environment with Anaconda, you can use Code: conda listCode: conda list regexHow to list all packages in the current environment? Code: conda listHow to list all packages installed into the environment Code: 'xyz'Code: conda list -n xyzRegex: How to list all packages starting with Code: 'abc'Code: conda list '^abc'The Code: pip freezeCode: abcCode: pip freezeOutput example (depending on your concrete environment/installation): Code: PS C:\Users\xcent> pip freeze
aaa==1.2.3
...
abc==1.2.3
...
zzz==1.2.3You can modify or exclude specific packages using the options provided in this screenshot: sourceMethod 8: pip freeze + grep on Linux/Ubuntu/macOS To check the versions of a single package on Linux/Ubuntu/macOS, you can chain Code: pip freezeCode: grep abcCode: pip freeze | grep abcCode: abcHere’s an example for Code: abcCode: pip freeze | grep abc
abc==1.2.3Check abc Installed Python How to check if Code: abcTo check if Code: abcCode: import abcCode: ModuleNotFoundErrorCode: try: import abc print("Module abc installed")
except ModuleNotFoundError: print("Module abc not installed")How to check the package version of Code: abcTo check which version of Code: abcCode: pip show abcCode: pip3 show abcCode: major.minor.patchCode: pip show abc # or pip3 show abc
# 1.2.3How to check my Code: abcTo check which version of Code: abcCode: pip show abcCode: pip3 show abcCode: pip show abc # or pip3 show abc
# 1.2.3How to check my Code: abcTo check which version of Code: abcCode: pip show abcCode: pip3 show abcCode: pip show abc # or pip3 show abc
# 1.2.3How to check my Code: abcTo check which version of Code: abcCode: pip show abcCode: pip3 show abcCode: pip show abc # or pip3 show abc
# 1.2.3How to check my Code: abcTo check which version of Code: abcCode: pip show abcCode: pip3 show abcCode: pip show abc # or pip3 show abc
# 1.2.3How to check my Code: abcTo check which version of Code: abcCode: !pip show abcCode: !Code: !pip show abcOutput: The following is an example on how this looks for Code: abcCode: Package Version
--------------- ---------
aaa 1.2.3
...
abc 1.2.3
...
zzz 1.2.3How to check the Code: abcUse Code: conda list 'abc'Code: conda list 'abc'How to check the Code: abcYou can use multiple commands to check the Code: abcCode: pip show abcCode: pip listCode: pip freezeCode: pip listCode: pip show abc
pip list
pip freeze
pip listThe former will output the specific version of Code: abcCode: abcCheck Package Version in VSCode or PyCharm How to check the Code: abcIntegrated Development Environments (IDEs) such as VSCode or PyCharm provide a built-in terminal where you can run Code: pip show abcCode: abcCode: pip show abc
pip3 show abc pip list
pip3 list pip freeze
pip3 freezeYou can type any of those commands in your IDE terminal like so: ![]() Summary In this article, you’ve learned those best ways to check a Python package version:
Thanks for giving us your valued attention — we’re grateful to have you here! ![]() Programmer Humor There are only 10 kinds of people in this world: those who know binary and those who don’t. ![]() ![]() ~~~ There are 10 types of people in the world. Those who understand trinary, those who don’t, and those who mistake it for binary. ![]() ![]() ![]() Related Tutorials
|