Linux 使用 pip 与 apt-get 安装软件包有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6874527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:21:06  来源:igfitidea点击:

What is the difference between installing a package using pip vs. apt-get?

pythonlinuxubuntupipapt-get

提问by Mridang Agarwalla

I'm trying to deploy a Django site on an Ubuntu machine. I need to install Psycopg2 and PIL but it seems that I'm able to install them using either apt-get or using pip. Is there a difference in installing by the two methods? I know that using pip, I'm able to install it into a virtual environment but with apt-get it installs in the global python environment.

我正在尝试在 Ubuntu 机器上部署一个 Django 站点。我需要安装 Psycopg2 和 PIL,但似乎我可以使用 apt-get 或使用 pip 安装它们。两种安装方式有区别吗?我知道使用 pip,我可以将它安装到虚拟环境中,但是使用 apt-get 将它安装在全局 python 环境中。

采纳答案by agf

You probably already know the benefits of apt-get. Automatic update notifications, other apt-installed packages that need those tools know they're installed, etc.

您可能已经知道 apt-get 的好处。自动更新通知、其他需要这些工具的 apt 安装包知道它们已安装等。

With pip, you know you're getting the latest version at the time you install it, you can install to a non-default version of Python, and you can install to a virtualenv.

使用 pip,您知道在安装时获得的是最新版本,您可以安装到 Python 的非默认版本,也可以安装到 virtualenv。

If you don't need any of the features pip gives you, and you don't routinely have to install other Python packages which aren't available over APT, use the APT versions.

如果您不需要 pip 为您提供的任何功能,并且您通常不必安装其他无法通过 APT 使用的 Python 包,请使用 APT 版本。

回答by Hugo Tavares

I always recommend installing Python package with pip, because some OS package managers do packages customizations, and it can either break or change package's behavior.

我总是建议使用 pip 安装 Python 包,因为一些操作系统包管理器会进行包定制,它可以破坏或改变包的行为。

If you need to install a package globally:

如果您需要全局安装软件包:

$ sudo pip install PACKAGE

And it will try to download your package from PyPIor project's links.

它会尝试从PyPI或项目的链接下载您的包。

回答by laviex

Most answers to this question miss one of the advantages using apt-get:

这个问题的大多数答案都忽略了使用的优势之一apt-get

apt-getis pre-compiled, which installs much fasterthan pip.

apt-get预编译的,安装速度pip.

To install numpy, matplotlib, pandas, and other scipy-related modules, apt-getonly takes seconds; pipcan easily consume 10min+.

安装numpy、matplotlib、pandas等scipy相关模块,apt-get只需几秒;pip可以轻松消耗10分钟+。

If you have root access and don't mind a little outdated versions, apt-getis the fast & worry-free way to go.

如果您有 root 访问权限并且不介意有点过时的版本,这apt-get是一种快速而无忧的方法。

回答by Andrei

You should be aware that what makes it in the package manager undergoes some integration testing, while what is in Pypi is untested.

您应该知道包管理器中的内容经过了一些集成测试,而 Pypi 中的内容未经测试。

Pypi is OK for development.

Pypi 可以用于开发。

In production, you may go with Pypi, but you will soon learn that you can always rely on what is in the package manager...

在生产中,您可能会使用 Pypi,但您很快就会了解到您始终可以依赖包管理器中的内容...

回答by Ysh

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.

您应该使用哪一个:apt-get 和 pip 都是成熟的包管理器,它们在安装时会自动安装任何其他包依赖项。您可以随意使用任何人。但是,如果您需要安装特定版本的 python-package,或者在 virtualenv 中安装包,或者安装仅托管在 PyPI 上的包;只有 pip 可以帮助您解决该问题。否则,如果您不介意在系统范围的位置安装软件包,那么使用 apt-get 还是 pip 并不重要。

回答by Charing Lau

I found something about this. My ubuntu has both python version 3.6 and 3.7. When apt install python3-xxx, xxx will be installed at /usr/lib/python3/dist-packages, but pip3 install xxx at /usr/local/lib/python3.7(my default python version)/dist-packages. And when change python to version 3.6, xxx installed by pip3 could not work, while installed by apt works fine.

我发现了一些关于这个的东西。我的 ubuntu 有 python 版本 3.6 和 3.7。apt install python3-xxx 时,xxx 将安装在 /usr/lib/python3/dist-packages,而 pip3 install xxx 在 /usr/local/lib/python3.7(我的默认 python 版本)/dist-packages。并且当将python更改为3.6版本时,pip3安装的xxx无法工作,而apt安装的则工作正常。