Find Installed Python Package Version Using Pip
When working with Python projects, it's important to know which versions of packages are installed in your environment. This helps ensure compatibility, manage dependencies, and troubleshoot issues effectively. Whether you're collaborating on a team, deploying an application, or simply maintaining your own codebase, being aware of the installed package versions is essential for a smooth development workflow. Let's understand the different method to do this efficiently.
Using pip show
The pip show command is one of the most straightforward ways to check the installed version of a package. It provides detailed information about the package, including the version number, location and dependencies.
- Open the terminal or command prompt.
- Type the following command and press Enter:
pip show package_name
Example: To check the version of emoji package, we would use:
pip show emoji
Output

Using import and __version__
If we are already in a Python environment, we can find out the version of a package by importing it and checking its __version__ attribute.
import emoji
print(emoji.__version__)
Output

Using Python -c Command
With -c flag we can run python code from the terminal.
python -c "import emoji; print('emoji:', emoji.__version__)"
Output

Using pip list
Another way to check the version of an installed package is by using the pip list command. This command lists all installed packages along with their versions.
pip list
Output
Scroll through the list to find the package name and its version number.

Using pip freeze
The pip freeze command is similar to pip list, but it formats the output in a way that's often used for creating requirements.txt files. It lists all installed packages with their exact versions.
pip freeze
Output
Find the package in the output to see its installed version.

To create a requirements.txt file with all installed packages and their versions, use the pip freeze command. The > symbol redirects the output to a file instead of showing it on the screen:
pip freeze > requriements.txt