“python setup.py install"和“pip install"之间的区别 [英] Difference between 'python setup.py install' and 'pip install'

查看:43
本文介绍了“python setup.py install"和“pip install"之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个外部包,我想从 tar 文件安装到我的 python virtualenv 中.安装软件包的最佳方法是什么?

I have an external package I want to install into my python virtualenv from a tar file. What is the best way to install the package?

我发现了两种方法:

  1. 解压 tar 文件,然后在解压后的目录中运行 python setup.py install.
  2. pip install packagename.tar.gz 来自 https://pip.pypa.io/en/stable/reference/pip_install/#examples

这两种方式是否有任何区别.

Is if there is any difference doing them in these 2 ways.

推荐答案

从表面上看,两者都做同样的事情:要么做 python setup.py install 要么 pip install 会为你安装你的 python 包,最小的麻烦.

On the surface, both do the same thing: doing either python setup.py install or pip install <PACKAGE-NAME> will install your python package for you, with a minimum amount of fuss.

然而,使用 pip 提供了一些额外的优势,使其更好用.

However, using pip offers some additional advantages that make it much nicer to use.

  • pip 会自动为你下载一个包的所有依赖项.相比之下,如果您使用 setup.py,您通常需要手动搜索和下载依赖项,这既乏味又令人沮丧.
  • pip 跟踪各种元数据,让您可以使用单个命令轻松卸载和更新软件包:pip uninstall pip install --upgrade .相比之下,如果您使用 setup.py 安装一个包,如果您想删除它,则必须手动删除和维护一个包,这可能很容易出错.莉>
  • 您不再需要手动下载文件.如果你使用setup.py,你必须访问图书馆的网站,找出下载它的位置,解压文件,运行setup.py...相反,pip 将自动搜索 Python 包索引 (PyPi) 以查看该包是否存在,并会自动下载,为您解压缩并安装该软件包.除了少数例外,几乎所有真正有用的 Python 库都可以在 PyPi 上找到.
  • pip 将让您轻松安装轮子,这是 Python 发行版的新标准.有关车轮的更多信息.
  • pip 提供了与使用 virtualenv 很好地集成在一起的额外好处,该程序可让您在计算机上运行需要冲突库和 Python 版本的多个项目.更多信息.
  • 从 Python 2.7.9 开始,Python 2.x 系列和 Python 3.x 系列从 Python 3.4.0 开始,pip 默认与 Python 捆绑在一起,使其更易于使用.
  • pip will automatically download all dependencies for a package for you. In contrast, if you use setup.py, you often have to manually search out and download dependencies, which is tedious and can become frustrating.
  • pip keeps track of various metadata that lets you easily uninstall and update packages with a single command: pip uninstall <PACKAGE-NAME> and pip install --upgrade <PACKAGE-NAME>. In contrast, if you install a package using setup.py, you have to manually delete and maintain a package by hand if you want to get rid of it, which could be potentially error-prone.
  • You no longer have to manually download your files. If you use setup.py, you have to visit the library's website, figure out where to download it, extract the file, run setup.py... In contrast, pip will automatically search the Python Package Index (PyPi) to see if the package exists there, and will automatically download, extract, and install the package for you. With a few exceptions, almost every single genuinely useful Python library can be found on PyPi.
  • pip will let you easily install wheels, which is the new standard of Python distribution. More info about wheels.
  • pip offers additional benefits that integrate well with using virtualenv, which is a program that lets you run multiple projects that require conflicting libraries and Python versions on your computer. More info.
  • pip is bundled by default with Python as of Python 2.7.9 on the Python 2.x series, and as of Python 3.4.0 on the Python 3.x series, making it even easier to use.

所以基本上,使用 pip.它仅提供对使用 python setup.py install 的改进.

So basically, use pip. It only offers improvements over using python setup.py install.

如果您使用的是旧版本的 Python,无法升级,并且没有安装 pip,您可以在以下链接中找到有关安装 pip 的更多信息:

If you're using an older version of Python, can't upgrade, and don't have pip installed, you can find more information about installing pip at the following links:

pip 本身并不需要教程.90% 的情况下,您真正​​需要的唯一命令是 pip install .也就是说,如果您有兴趣了解有关 pip 究竟可以做什么的详细信息,请参阅:

pip, by itself, doesn't really require a tutorial. 90% of the time, the only command you really need is pip install <PACKAGE-NAME>. That said, if you're interested in learning more about the details of what exactly you can do with pip, see:

通常也建议您将 pip 和 virtualenv 一起使用.如果您是 Python 的初学者,我个人认为开始时只使用 pip 并全局安装包是可以的,但最终我确实认为您应该在处理更严肃的项目时过渡到使用 virtualenv.

It is also commonly recommended that you use pip and virtualenv together. If you're a beginner to Python, I personally think it'd be fine to start of with just using pip and install packages globally, but eventually I do think you should transition to using virtualenv as you tackle more serious projects.

如果您想详细了解如何同时使用 pip 和 virtualenv,请参阅:

If you'd like to learn more about using pip and virtualenv together, see:

这篇关于“python setup.py install"和“pip install"之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆