![]() |
|
[Tut] How to Check ‘future’ 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 ‘future’ Package Version in Python? (/thread-99727.html) |
[Tut] How to Check ‘future’ Package Version in Python? - xSicKxBot - 07-21-2022 How to Check ‘future’ 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: futureCode: futureThese are the eight best ways to check the installed version of the Python module Code: future
Before we go into these ways to check your Code: futureA 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: futureMethod 1: pip show To check which version of the Python library Code: futureCode: pip show futureCode: pip3 show futureThis 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 future
Name: future
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 future
python3 -m pip show future
py -m pip show future
pip3 show futureNext, we’ll dive into more ways to check your Code: future![]() 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: futureThis 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
...
future 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 futureCode: pip3 list | findstr futureCode: futureHere’s an example for Code: futureCode: pip3 list | findstr future 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('future')Code: futureCode: 1.2.3Here’s the code: Code: import importlib.metadata
print(importlib.metadata.version('future'))
# 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: 'future'Code: conda list '^future'The Code: pip freezeCode: futureCode: pip freezeOutput example (depending on your concrete environment/installation): Code: PS C:\Users\xcent> pip freeze
aaa==1.2.3
...
future==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 futureCode: pip freeze | grep futureCode: futureHere’s an example for Code: futureCode: pip freeze | grep future
future==1.2.3Check future Installed Python How to check if Code: futureTo check if Code: futureCode: import futureCode: ModuleNotFoundErrorCode: try: import future print("Module future installed")
except ModuleNotFoundError: print("Module future not installed")How to check the package version of Code: futureTo check which version of Code: futureCode: pip show futureCode: pip3 show futureCode: major.minor.patchCode: pip show future # or pip3 show future
# 1.2.3How to check my Code: futureTo check which version of Code: futureCode: pip show futureCode: pip3 show futureCode: pip show future # or pip3 show future
# 1.2.3How to check my Code: futureTo check which version of Code: futureCode: pip show futureCode: pip3 show futureCode: pip show future # or pip3 show future
# 1.2.3How to check my Code: futureTo check which version of Code: futureCode: pip show futureCode: pip3 show futureCode: pip show future # or pip3 show future
# 1.2.3How to check my Code: futureTo check which version of Code: futureCode: pip show futureCode: pip3 show futureCode: pip show future # or pip3 show future
# 1.2.3How to check my Code: futureTo check which version of Code: futureCode: !pip show futureCode: !Code: !pip show futureOutput: The following is an example on how this looks for Code: futureCode: Package Version
--------------- ---------
aaa 1.2.3
...
future 1.2.3
...
zzz 1.2.3How to check the Code: futureUse Code: conda list 'future'Code: conda list 'future'How to check the Code: futureYou can use multiple commands to check the Code: futureCode: pip show futureCode: pip listCode: pip freezeCode: pip listCode: pip show future
pip list
pip freeze
pip listThe former will output the specific version of Code: futureCode: futureCheck Package Version in VSCode or PyCharm How to check the Code: futureIntegrated Development Environments (IDEs) such as VSCode or PyCharm provide a built-in terminal where you can run Code: pip show futureCode: futureCode: pip show future
pip3 show future 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
|