Working on a Python project may require listing installed Python packages in order to manage dependencies, check for updates, or share project requirements with others. In this article, we will look at various techniques for listing the Python packages installed on a system.
List installed Python packages
Here are some ways we can list installed Python packages:
- Using pip list
- Freeze using pip
- Using Python’s pkg_resources
- Use pipdeptree
- Use pipenv
- Using Jupyter Notebooks
Use pip list to list installed Python packages
The most common way to list installed Python packages is to use the pip command line tool. pip is Python’s standard package manager, and it comes pre-installed with Python 3.4 and above.
We can use the list command to list the packages that have been installed using pip. Just open a terminal or command prompt and run the following command and you will see a list of all installed packages.
python Copy code pip list
This command will display a list of all Python packages installed in the Python environment and their versions. You can also redirect the output to a text file (optional) If you want to save the list of installed packages to a text file, you can use the following command:
python Copy code pip list > installed_packages.txt
This command creates a file named installed_packages.txt and saves the package list in it.
Use pip freeze to list Python packages
Another commonly used command to list installed packages, especially in a Python project management context, is pip freeze. This command generates a list of installed packages and their versions in a format typically used to specify project dependencies in a requirements.txt file.
We can use pip freeze to list installed Python packages. Just open a terminal or command prompt and run the following commands.
python Copy code pip freeze
This command will display a list of installed packages and their versions, similar to what you might find in the requirements.txt file.
List Python packages using Python’s pkg_resources module
If you prefer to programmatically list installed packages from a Python script, you can use the pkg_resources module from the setuptools package. Here’s an example of how to use it:
python Copy code import pkg_resources installed_packages = pkg_resources.working_set for package in installed_packages: print(f"{package.key}=={package.version}")
This script will print the names and versions of all installed packages in your Python environment.
Use pipdeptree to list Python packages
pipdeptree is a Python package that helps you visualize and list the dependencies of installed packages in a tree structure. To use it, you need to install it first:
python Copy code pip install pipdeptree
After installing pipdeptree, you can list installed packages and their dependencies as follows:
python Copy code pipdeeptree
This command will display a tree structure of installed packages and their dependencies.
Use pipelinev to list installed packages
Pipenv is a popular tool for managing Python project environments and dependencies. It combines pip and virtualenv to create isolated Python environments for your projects. To list installed packages in a Pipenv environment, follow these steps:
- Open a terminal or command prompt and navigate to the directory where Pipfile is located.
- Activate the virtual environment:
python Copy code pipenv shell
List installed packages:
python Copy code pipenv lock --requirements
This command will display a list of installed packages and their versions.
Using Jupyter Notebook
If we are using Jupyter Notebook for Python development and want to list the installed packages in the notebook, we can use the ! (shell command) prefix. That’s it:
- Open Jupyter Notebook: Start Jupyter Notebook by running jupyter Notebook in the terminal.
- Create a new notebook or open an existing notebook: You can create a new notebook or open an existing notebook to list installed packages.
- List installed packages in a notebook unit:
python Copy code !pip list
Running this command in a notebook cell will display a list of installed packages and their versions in the notebook output.
Digression
In this era of rapidly growing technology, programming is like a ticket to a world of infinite possibilities for many people. Among the star lineup of programming languages, Python is like the dominant superstar. With its concise and easy-to-understand syntax and powerful functions, Python stands out and becomes one of the hottest programming languages in the world.
The rapid rise of Python is extremely beneficial to the entire industry, but “There are many popular people and not many people
“, which has led to a lot of criticism, but it still cannot stop its popularity. development momentum.
If you are interested in Python and want to learn Python, here I would like to share with you a Complete set of Python learning materials, which I compiled during my own study. I hope it can help you, let’s work together!
Friends in need can click the link below to get it for free or Scan the QR code below to get it for free
CSDN Gift Package: Free sharing of the most complete “Python learning materials” on the entire network(safe link, click with confidence )
?
1Getting started with zero basics
① Learning route
For students who have never been exposed to Python, we have prepared a detailed Learning and Growth Roadmap for you. It can be said to be the most scientific and systematic learning route. You can follow the above knowledge points to find corresponding learning resources to ensure that you learn more comprehensively.
② Route corresponding learning video
There are also many learning videos suitable for beginners. With these videos, you can easily get started with Python~
③Exercise questions
After each video lesson, there are corresponding exercises to test your learning results haha!
2Domestic and foreign Python books and documents
① Documents and books
3Python toolkit + project source code collection
①Python toolkit
The commonly used development software for learning Python is here! Each one has a detailed installation tutorial to ensure you can install it successfully!
②Python practical case
Optical theory is useless. You must learn to type code along with it and practice it in order to apply what you have learned to practice. At this time, you can learn from some practical cases. 100+ practical case source codes are waiting for you!
③Python mini game source code
If you feel that the practical cases above are a bit boring, you can try writing your own mini-game in Python to add a little fun to your learning process!
4Python interview questions
After we learn Python, we can go out and find a job if we have the skills! The following interview questions are all from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and Alibaba bosses have given authoritative answers. I believe everyone can find a satisfactory job after reviewing this set of interview materials.
5Python part-time channel
Moreover, after learning Python, you can also take orders and make money on major part-time platforms. I have compiled various part-time channels + part-time precautions + how to communicate with customers into documents.
All the above information , if friends need it, you can scan the QR code below to get it for free
?