To check the versions of a single package on Linux/Ubuntu/macOS, you can chain pip freeze with grep xyz using the CMD or Powershell command: pip freeze | grep xyz to programmatically locate the version of your particular package xyz in the output list of package versions. Source Method 8: pip freeze + grep on Linux/Ubuntu/macOS You can modify or exclude specific packages using the options provided in this screenshot: Output from my local Windows environment with PowerShell (strange packages I know) ): PS C:\Users\xcent> pip freezeįor example, I have the Python package openpyxl installed with version 3.0.10. You can spot your specific package if it is installed in the environment. The pip freeze command without any option lists all installed Python packages in your environment in alphabetically order (ignoring UPPERCASE or lowercase). Regex: How to list all packages starting with 'py' or 'code'? conda list '^(py|code)' Method 7: pip freeze Regex: How to list all packages starting with 'py'? conda list '^py' How to list all packages installed into the environment 'xyz'? conda list -n xyz How to list all packages in the current environment? conda list Optionally, you can add a regular expression using the syntax conda list regex to list only packages matching a certain pattern. If you have created your Python environment with Anaconda, you can use conda list to list all packages installed in your (virtual) environment. For example, ('numpy') returns 1.21.0 in my current environment. This returns a string representation of the specific version. The tadata library provides a general way to check the package version in your Python script via ('xyz') for library xyz. In the PEP author’s own email archives, the earliest example of the use of an _version_ module attribute by independent module developers dates back to 1995.” Method 5: “ PEP 8 describes the use of a module attribute called _version_ for recording “Subversion, CVS, or RCS” version strings using keyword expansion. Here’s an excerpt from the PEP 8 docs mentioning the _version_ attribute. Not all packages provide this attribute but as it is recommended by PEP, it’ll work for most libraries. To check your package installation in your Python script, you can also use the xyz._version_ attribute of the particular library xyz. Here’s an example for numpy: pip3 list | findstr numpyġ.21.0 Method 4: Library._version_ Attribute To check the versions of a single package on Windows, you can chain pip list with findstr xyz using the CMD or Powershell command: pip3 list | findstr numpy to locate the version of your particular package xyz in the output list of package versions automatically. Pip3 list Method 3: pip list + findstr on Windows Then try those commands before giving up: python -m pip list In some instances, this will not work-depending on your environment. Here’s an example in my Windows Powershell, I’ve highlighted the line that shows that my package version is 1.21.0: PS C:\Users\xcent> pip list This will work if your pip installation is version 1.3 or higher. To check the versions of all installed packages, use pip list and locate the version of your particular package in the output list of package versions sorted alphabetically. Of course, replace “ numpy” with your particular package name. In this case, try those commands before giving up: python -m pip show numpy Location: c:\users\xcent\appdata\local\programs\python\python39\lib\site-packages Summary: NumPy is the fundamental package for array computing with Python. Here’s an example in my Windows Powershell for NumPy: I’ve highlighted the line that shows that my package version is 1.21.0: PS C:\Users\xcent> pip show numpy This 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!! For example, to check the version of your NumPy installation, run pip show numpy in your CMD/Powershell (Windows), or terminal (macOS/Linux/Ubuntu). To check which version of a given Python library, say xyz, is installed, use pip show xyz or pip3 show xyz. Let’s dive into some examples for each of those next! Method 1: pip show Method 3: pip list | findstr my_package.These are the eight best ways to check the version of a Python module: In this article, I’ll show you how to check the version of a Python module (package, library).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |