The love-hate relationship between pip and conda in Python

When using pip and conda, have you ever had the following doubts? ? ?

At present, only the following common confusions are summarized. If scholars have other doubts, please leave a message to discuss. I will answer and update to help myself sort out and help other scholars who are also confused. Thank you!

The connection and difference between pip and conda

pip is lighter and simpler, and conda is more comprehensive and powerful.

Both pip and conda are Python package management tools, and they have connections and differences:

connect

  • Both can be used to install, uninstall and manage Python packages.
  • Both can connect to PyPI to install Python packages. conda can also connect to Anaconda cloud.
  • Both can export the package information of the current environment.
  • Both can create a Python virtual environment.

the difference

  • pip is built into Python and conda is part of the Anaconda/Miniconda distribution.
  • pip can only manage Python packages, and conda can manage packages in Python, R and other languages ​​across languages.
  • pip cannot directly manage different Python environments, conda can easily manage multiple environments.
  • pip depends on Python, conda can exist alone.
  • The pip installation source is only obtained from PyPI, and the conda can be obtained from the Anaconda cloud.
  • pip needs virtualenv to manage the virtual environment, and conda comes with environment management.
  • The components of pip are more simple, and conda integrates functions such as package management and environment management.

When to use pip and when to use conda

Considering the project requirements comprehensively, the two can be used together to give full play to their respective advantages.

Prefer using pip

  • When only Python packages need to be installed. pip is more focused on Python package management.
  • When Anaconda/Miniconda is not installed in the system. pip is Python's built-in package management tool.
  • When a Python virtual environment needs to be used. pip + virtualenv can facilitate the management of virtual environments.
  • When you need to install some third-party libraries that only provide wheel files. pip has better support for wheel files.
  • When a lightweight package management tool is required, or is not sensitive to environmental dependencies. pip is lighter and simpler.

Prefer using conda

  • When inter-language dependencies need to be installed, such as Python and R packages. conda supports multilingual package management.
  • When you need to port your environment across operating systems. conda can export interoperable environment configurations.
  • When you need to manage multiple independent Python environments. Conda environment management is more convenient.
  • When needed to avoid environment dependency issues. conda is more comprehensive for package dependency parsing.
  • When management of system-level components is required. conda can install some system-level components.
  • When you need to use other features in the Anaconda distribution. conda provides more comprehensive functionality.

The difference between pip install and conda install

different sources

  • pip is Python's default package management tool, bundled with Python.
  • conda is a package management tool specific to the Anaconda/Miniconda distribution.

Dependency management differences

  • pip can only manage dependencies for Python packages.
  • conda can manage package dependencies in various languages ​​such as Python and R across languages.

Differences in Environmental Management

  • pip cannot directly manage different Python environments.
  • conda can easily manage multiple independent Python environments.

different package sources

  • By default, pip packages come from the Python Package Index (PyPI).
  • The conda installation package can come from Anaconda's own warehouse or from PyPI.

System Environment Requirements

  • pip has low requirements on the system environment.
  • conda has certain requirements on the system environment, and Miniconda/Anaconda needs to be pre-installed.

In the same virtual environment, pip list and conda list show different

Both pip and conda have their own package management logic, so in the same environment, if you install the same package from the same channel, the final installation package may be different because of their respective algorithms and specifications.

  1. pip and conda use different package repositories by default. By default, pip only accesses the Python packages on PyPI, while conda accesses both the Anaconda repository and PyPI by default.

  2. Even if the same package is installed, due to the different dependency resolution algorithms of pip and conda, the installed dependency packages may be different. This causes them to end up with different installed components.

  3. For some cross-language packages, such as R language packages, conda can recognize and install them, but pip cannot recognize these non-Python packages.

  4. For some Python packages that only provide wheel format files, pip can be installed directly, but conda may need to compile and install from source code.

  5. The package version detection algorithms of pip and conda are different, which may cause different versions of the same package to be installed.

  6. When the virtual environment is created, conda will pre-install some packages it considers important by default, but pip will not.

  7. The package name specifications of pip and conda are slightly different, which may also cause some package METADATA information to be inconsistent.

Supongo que te gusta

Origin blog.csdn.net/qq_40280673/article/details/132559533
Recomendado
Clasificación