转自https://askubuntu.com/questions/431780/apt-get-install-vs-pip-install
pip和apt的区别
PyPI is the Python Package Index — a repository of python modules.
pip
is used to download and install packages directly from PyPI. PyPI is hosted by Python Software Foundation. It is a specialized package manager that only deals with python packages.
apt-get
is used to download and install packages from Ubuntu repositories which are hosted by Canonical.
Some of the differences between installing python packages from apt-get
and pip
are as follows:
-
Canonical only provides packages for selected python modules. Whereas, PyPI hosts a much broader range of python modules. So, there are a lot of python modules which you won't be able to install using
apt-get
. -
Canonical only hosts a single version of any package (generally the latest or the one released in recent past). So, with
apt-get,
we cannot decide the version of python-package that we want.pip
helps us in this situation. We can install any version of the package that has previously been uploaded on PyPI. This is extremely helpful in case of conflict in dependencies. -
apt-get
installs python modules in system-wide location. We cannot just install modules in our project virtualenv.pip
solves this problem for us. If we are usingpip
after activating the virtualenv, it is intelligent enough to only install the modules in our project virtualenv. As mentioned in the previous point, if there is a version of a particular python package already installed in a system-wide location, and one of our projects requires an older version of the same python package, in such situations we can use virtualenv and pip to install that older version of python package without any conflicts. -
As @Radu Rădeanu pointed out in this answer, there would generally be the difference in names of packages as well. Canonical usually names Python 2 packages as
python-<package_name>
and Python 3 packages aspython3-<package_name>
. Whereas forpip
we generally just need to use<package_name>
for both Python 2 as well as Python3 packages.
Which one should you use:
Both apt-get
and pip
are mature package managers which automatically install any other package dependency while installing. You may use anyone as you like. However, if you need to install a particular version of python-package, or install the package in a virtualenv, or install a package which is only hosted on PyPI; only pip
would help you solve that issue. Otherwise, if you don't mind installing the packages in system-wide location it doesn't really matter whether you use apt-get
or pip
.