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

查看:635
本文介绍了'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?

我发现了两种可以做到这一点的方法:

I've discovered 2 ways that can do it:

  1. 提取tar文件,然后在提取的目录中运行python setup.py install.
  2. pip install packagename.tar.gz .io/zh-CN/stable/reference/pip_install/#examples
  1. Extract the tar file, then run python setup.py install inside of the extracted directory.
  2. pip install packagename.tar.gz from example # 7 in 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 installpip install <PACKAGE-NAME>都会为您安装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 <PACKAGE-NAME>pip install --upgrade <PACKAGE-NAME>轻松卸载和更新软件包.相反,如果使用setup.py安装软件包,则要想摆脱它,必须手动手动删除和维护该软件包,这可能容易出错.
  • 您不再需要手动下载文件.如果使用setup.py,则必须访问图书馆的网站,弄清楚从何处下载文件,解压缩文件,然后运行setup.py....相反,pip会自动搜索轻松安装滚轮,这是Python发行版的新标准. 有关车轮的更多信息.
  • pip提供了与使用virtualenv良好集成的其他好处,该程序使您可以运行多个项目,这些项目需要在计算机上使用冲突的库和Python版本. 更多信息.
  • pip默认情况下与Python 2.x系列的Python 2.7.9及更高版本(Python 3.x系列的Python 3.4.0及更高版本)捆绑在一起.
  • 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:

  • Official instructions on installing pip for all operating systems
  • Instructions on installing pip on Windows (including solutions to common problems)
  • Instructions on installing pip for Mac OX

pip本身并不需要教程. 90%的时间,您真正需要的唯一命令是pip install <PACKAGE-NAME>.就是说,如果您想了解更多有关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:

  • Quickstart guide
  • Official documentation.

通常也建议同时使用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:

  • Why you should be using pip and virtualenv
  • A non-magical introduction to Pip and Virtualenv for Python beginners
  • Virtual Environments

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

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