杰瑞科技汇

Python manager list如何高效管理依赖包?

Of course! The phrase "Python manager list" can mean a few different things. I'll cover the most common interpretations, from the most likely meaning to others you might be looking for.

Python manager list如何高效管理依赖包?-图1
(图片来源网络,侵删)

The Most Likely Meaning: A List of Python Package Managers

This is probably what you're looking for. A package manager is a tool that automates the process of installing, updating, and removing Python libraries (packages) and their dependencies.

Here is a list of the most important Python package managers, from the essential to the more specialized.


The Essential Trio: pip, venv, and py

These three tools are bundled with modern Python installations and are fundamental to any Python project.

Manager What It Is Primary Use Case Key Command Example
pip The Package Installer for Python. It's the standard tool for installing packages from the Python Package Index (PyPI). Installing third-party libraries for your project. pip install requests
venv Virtual Environment Creator. It creates isolated, self-contained Python environments. This is crucial for managing dependencies per project. Creating project-specific environments to avoid dependency conflicts. python -m venv my-project-env
py The Python Launcher. A cross-platform command-line tool that helps manage multiple Python versions installed on your system. Running scripts with a specific Python version or finding where Python is installed. py -3.11 my_script.py

The Modern Standard: pip + venv in a pyproject.toml World

This is the current best-practice workflow, standardized by the PEP 518 and PEP 621 specifications.

Python manager list如何高效管理依赖包?-图2
(图片来源网络,侵删)
Tool/Concept What It Is Role in the Workflow
pip The installer. Installs packages, both from pyproject.toml and directly.
venv The environment creator. Creates an isolated space for your project's dependencies.
pyproject.toml A configuration file (using TOML format). Defines project metadata, dependencies, and build requirements in a standardized way.
Build Backends (e.g., setuptools, flit, hatchling) Tools that read pyproject.toml and build your package. They are used by pip to install your project in "editable" mode (pip install -e .).

Typical Modern Workflow:

  1. python -m venv .venv
  2. .venv\Scripts\activate (on Windows) or source .venv/bin/activate (on macOS/Linux)
  3. pip install -e . (installs your project and its dependencies from pyproject.toml)

High-Level Project and Dependency Management

These tools are built on top of pip and venv to provide more powerful features like lockfiles and dependency management across multiple environments.

Manager What It Is Primary Use Case Key Command Example
Poetry A comprehensive tool for dependency management and packaging. It manages pyproject.toml, creates virtual environments, and builds/publishes packages. Full project lifecycle management, especially for libraries and complex applications. poetry add pandas
PDM A modern Python package and dependency manager that respects pyproject.toml. It uses a lockfile and is known for its speed and PEP 621 compliance. A powerful, fast, and modern alternative to Poetry, especially for teams. pdm add numpy
Hatch A full-featured project management and packaging system. It provides a powerful build backend and a plugin system for tools like hatch env and hatch build. Robust project management with a strong focus on extensibility and developer experience. hatch run test

Specialized and Legacy Managers

These tools are used for specific purposes or are older but still relevant in certain contexts.

Manager What It Is Primary Use Case Key Command Example
Conda A cross-platform language-agnostic binary package and environment manager. It handles non-Python dependencies (like C libraries) very well. Scientific computing (data science, machine learning), managing complex C/C++ dependencies. conda install tensorflow
easy_install The predecessor to pip. It was the standard for Python 2. (Legacy) Installing packages in older Python 2 projects. easy_install flask
setuptools A library for packaging Python projects. Its setup.py script was the traditional way to define project metadata and dependencies. (Legacy/Legacy migration) Defining packages for older projects or when pyproject.toml is not an option. python setup.py install

Other Possible Meanings

A) How to List Installed Packages with pip

If you meant "how do I list the packages installed in my Python environment?", you use pip.

Python manager list如何高效管理依赖包?-图3
(图片来源网络,侵删)

List all installed packages:

pip list

This will show you a simple list of package names and versions.

List packages with detailed output (useful for copying):

pip list --format=freeze

This is the output you would typically copy into a requirements.txt file.

List outdated packages:

pip list --outdated

This is very useful for seeing which packages have newer versions available.

B) How to List Available Environments

If you meant "how do I list the virtual environments I have created?", the answer depends on your tool.

  • For venv environments: You typically have to look in your project folders. There's no global venv command to list them all. They are usually named .venv, venv, or env.

  • For conda environments: Conda has a built-in command for this.

    conda env list
    # or the shorter version
    conda env list
  • For venv/pip environments managed by a tool like PDM:

    pdm show envs

Summary and Recommendation

If you want to... Use this tool...
Install a library pip
Isolate a project's dependencies venv
Manage a complete project (dependencies, env, builds) Poetry or PDM
Work in data science (handle C libs) Conda
See what's installed in your current env pip list
See what virtual environments you have conda env list (for conda) or check your folders (for venv)

For most new Python projects today, the recommended stack is pip + venv + pyproject.toml. For a more streamlined, all-in-one experience, Poetry or PDM are excellent choices.

分享:
扫描分享到社交APP
上一篇
下一篇