安装PIP软件包的最佳方法(Ubuntu/Linux)

发布于 2025-02-03 21:02:34 字数 1394 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

成熟稳重的好男人 2025-02-10 21:02:34

不要将sudopip一起使用。您有可能覆盖系统安装的软件包,然后弄乱您的操作系统。

sudo apt install< python-package>非常安全,但可能会导致过时的软件包,并且绝对不会包括您可能想要安装的所有软件包。

pip3 install< package>将仅为当前用户安装软件包(因此,不在系统范围内;如果您是唯一的用户,那么您就可以了),这是我建议的。

进一步,虚拟环境或使用conda(“扩展”虚拟环境管理器)甚至可能更安全,而要花费更多的工作来设置,还有更多的磁盘空间(通常,后者无关紧要)。

您将不得不阅读使用虚拟环境或CONDA的使用。这个主题在这里有标准答案太长。

Don't use sudo with pip. There is a chance you'll overwrite system-installed packages, and mess up your OS.

sudo apt install <python-package> is pretty safe, but may result in outdated packages, and will definitely not include all packages you may want to install.

pip3 install <package> will install packages for just the current user (thus, not system-wide; if you're the only user, you're fine), and is what I would recommend.

Going further, virtual environment or use of Conda (an "extended" virtual environment manager) are potentially even safer, at the cost of a little more work to set up, and a bit more disk space (usually, the latter is insignificant).

You will have to read up on the use of virtual environment or Conda. That topic is too long for a standard answer here.

花开柳相依 2025-02-10 21:02:34

我建议作为第一步阅读包文档,因为它通常包含有关如何安装它的信息。 的几个示例

在您的计算机中检查到哪个版本python(通过检查python的输出 - - version),如果是python 2,并且要将软件包安装到python 3,则需要使用pip3python3而不是pippython,如果是python 3,则可以按照命令来使用命令。

I would suggest as first step reading package documentation, as it often contains information regarding how to install it. Few examples regarding popular packages

  • click suggests pip install click
  • jinja2 suggests pip install Jinja2
  • requests suggests python -m pip install requests

Before that check to what version pertains python in your machine (by checking output of python --version), if it is Python 2 and you want to install packages to Python 3, then you need to use pip3 and python3 rather than pip and python, if it is Python 3 you might use command as they are.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文