Python是否具有程序包/模块管理系统?

问题:Python是否具有程序包/模块管理系统?

Python是否具有包/模块管理系统,类似于Ruby在哪里可以使用rubygems gem install packagename

在“ 安装Python模块”上,我仅看到对的引用python setup.py install,但这需要您首先找到该软件包。

Does Python have a package/module management system, similar to how Ruby has rubygems where you can do gem install packagename?

On Installing Python Modules, I only see references to python setup.py install, but that requires you to find the package first.


回答 0

最近的进展

2014年3月:好消息!Pip随附了Python 3.4。Pip长期以来一直是Python的事实上的标准包管理器。您可以这样安装软件包

pip install httpie

哇!这是所有Python版本中的最佳功能。它使每个人都可以访问社区丰富的图书馆。新手不再因设置困难而无法使用社区库。

但是,Python打包经验仍然有许多令人沮丧的地方。累积地,它们使Python对新手来说非常不受欢迎。而且,长期的忽视历史(即从Python 2.0到Python 3.3一直没有使用包管理器交付14年)确实对社区造成了损害。我在下面描述。

突出的挫败感

重要的是要了解,尽管经验丰富的用户能够解决这些问题,但它们却是Python新手的重大障碍。实际上,困难和普遍的用户不友好可能阻止了其中许多人。

PyPI网站是有帮助的

每种带有程序包管理器的语言都有一个官方(或准官方)存储库,供社区下载和发布程序包。Python具有Python包索引PyPI。 https://pypi.python.org/pypi

让我们将其页面与RubyGems和Npm(节点包管理器)的页面进行比较。

  1. https://rubygems.org/gems/rails软件包的RubyGems页面rails
  2. https://www.npmjs.org/package/express软件包的Npm页面express
  3. https://pypi.python.org/pypi/simplejson/软件包的PyPI页面simplejson

您将看到RubyGems和Npm页面均以该程序包的一行说明开始,然后是如何安装的友好说明。

同时,天真地浏览到PyPI的所有不幸的Python用户都会遇到麻烦。在https://pypi.python.org/pypi/simplejson/上,他们找不到任何有用的说明。但是,有一个绿色的大“下载”链接。遵循它并非没有道理。啊哈,他们点击!他们的浏览器下载.tar.gz文件。许多Windows用户甚至无法打开它,但是如果他们坚持不懈,他们最终可能会提取它,然后运行setup.py并最终在Google的帮助下运行setup.py install。有些人会放弃并重新发明轮子。

当然,所有这些都是错误的。安装软件包的最简单方法是使用Pip命令。但是PyPI甚至没有提到Pip。相反,它引导他们走下了一条古老而乏味的道路。

错误:找不到vcvarsall.bat

Numpy是Python最受欢迎的库之一。尝试使用Pip安装它,您会收到以下错误消息:

错误:找不到vcvarsall.bat

尝试解决此问题是Stack Overflow上最受欢迎的问题之一:“ 错误:无法找到vcvarsall.bat

很少有人能成功。

为了进行比较,在相同情况下,Ruby会显示此消息,该消息说明了正在发生的事情以及如何修复它:

请更新您的PATH以包括构建工具,或从http://rubyinstaller.org/downloads下载DevKit 并按照http://github.com/oneclick/rubyinstaller/wiki/Development-Kit上的说明进行操作

发布包很难

Ruby和Nodejs随附功能齐全的软件包管理器Gem(自2007年起)和Npm(自2011年起),并培育了以GitHub为中心的共享社区。Npm使发布软件包就像安装它们一样容易,它已经有64k软件包。RubyGems列出了72k个软件包。古老的Python软件包索引列出41k

历史

面对“ 包含电池 ”的座右铭,直到2014年Python一直没有包装管理器发货。

在Pip之前,事实上的标准是一个命令 easy_install。真是太糟糕了。was no命令用于卸载软件包。

点子是一个巨大的进步。它具有Ruby’s Gem的大多数功能。不幸的是,直到最近,Pip一直很难安装。实际上,该问题仍然是Stack Overflow上最重要的Python问题:“ 如何在Windows上安装pip?

Recent progress

March 2014: Good news! Python 3.4 ships with Pip. Pip has long been Python’s de-facto standard package manager. You can install a package like this:

pip install httpie

Wahey! This is the best feature of any Python release. It makes the community’s wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup.

However, there remains a number of outstanding frustrations with the Python packaging experience. Cumulatively, they make Python very unwelcoming for newbies. Also, the long history of neglect (ie. not shipping with a package manager for 14 years from Python 2.0 to Python 3.3) did damage to the community. I describe both below.

Outstanding frustrations

It’s important to understand that while experienced users are able to work around these frustrations, they are significant barriers to people new to Python. In fact, the difficulty and general user-unfriendliness is likely to deter many of them.

PyPI website is counter-helpful

Every language with a package manager has an official (or quasi-official) repository for the community to download and publish packages. Python has the Python Package Index, PyPI. https://pypi.python.org/pypi

Let’s compare its pages with those of RubyGems and Npm (the Node package manager).

  1. https://rubygems.org/gems/rails RubyGems page for the package rails
  2. https://www.npmjs.org/package/express Npm page for the package express
  3. https://pypi.python.org/pypi/simplejson/ PyPI page for the package simplejson

You’ll see the RubyGems and Npm pages both begin with a one-line description of the package, then large friendly instructions how to install it.

Meanwhile, woe to any hapless Python user who naively browses to PyPI. On https://pypi.python.org/pypi/simplejson/ , they’ll find no such helpful instructions. There is however, a large green ‘Download’ link. It’s not unreasonable to follow it. Aha, they click! Their browser downloads a .tar.gz file. Many Windows users can’t even open it, but if they persevere they may eventually extract it, then run setup.py and eventually with the help of Google setup.py install. Some will give up and reinvent the wheel..

Of course, all of this is wrong. The easiest way to install a package is with a Pip command. But PyPI didn’t even mention Pip. Instead, it led them down an archaic and tedious path.

Error: Unable to find vcvarsall.bat

Numpy is one of Python’s most popular libraries. Try to install it with Pip, you get this cryptic error message:

Error: Unable to find vcvarsall.bat

Trying to fix that is one of the most popular questions on Stack Overflow: “error: Unable to find vcvarsall.bat

Few people succeed.

For comparison, in the same situation, Ruby prints this message, which explains what’s going on and how to fix it:

Please update your PATH to include build tools or download the DevKit from http://rubyinstaller.org/downloads and follow the instructions at http://github.com/oneclick/rubyinstaller/wiki/Development-Kit

Publishing packages is hard

Ruby and Nodejs ship with full-featured package managers, Gem (since 2007) and Npm (since 2011), and have nurtured sharing communities centred around GitHub. Npm makes publishing packages as easy as installing them, it already has 64k packages. RubyGems lists 72k packages. The venerable Python package index lists only 41k.

History

Flying in the face of its “batteries included” motto, Python shipped without a package manager until 2014.

Until Pip, the de facto standard was a command easy_install. It was woefully inadequate. The was no command to uninstall packages.

Pip was a massive improvement. It had most the features of Ruby’s Gem. Unfortunately, Pip was–until recently–ironically difficult to install. In fact, the problem remains a top Python question on Stack Overflow: “How do I install pip on Windows?


回答 1

Python包索引(PyPI)似乎是标准的:

  • 安装软件包: pip install MyProject
  • 更新pip install --upgrade MyProject
  • 解决一个版本的一揽子pip install MyProject==1.0

您可以如下安装软件包管理器:

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

参考文献:

The Python Package Index (PyPI) seems to be standard:

  • To install a package: pip install MyProject
  • To update a package pip install --upgrade MyProject
  • To fix a version of a package pip install MyProject==1.0

You can install the package manager as follows:

curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
easy_install pip

References:


回答 2

只是为了形成对比,还有一点

And just to provide a contrast, there’s also pip.


回答 3

作为Ruby和Perl开发人员和学习Python的人,我还没有发现easy_install或pip等同于RubyGems或CPAN。

当开发人员更新模块时,我倾向于使我的开发系统运行最新版本的模块,并将生产系统冻结为固定版本。RubyGems和CPAN都可以通过列出可用的模块轻松地找到模块,然后进行安装,然后根据需要单独或批量更新。

easy_install和pip使得安装模块变得容易,一旦我通过浏览器搜索找到了它,或者通过其他方法了解了它,但是它们不会告诉我有什么可用。我可以明确命名要更新的模块,但是这些应用程序不会告诉我已更新的内容,也不会在需要时批量更新所有内容。

因此,pip和easy_install中提供了基本功能,但是我希望看到一些缺少的功能,这些功能使它们更友好,更易于使用,并且与CPAN和RubyGems相当。

As a Ruby and Perl developer and learning-Python guy, I haven’t found easy_install or pip to be the equivalent to RubyGems or CPAN.

I tend to keep my development systems running the latest versions of modules as the developers update them, and freeze my production systems at set versions. Both RubyGems and CPAN make it easy to find modules by listing what’s available, then install and later update them individually or in bulk if desired.

easy_install and pip make it easy to install a module ONCE I located it via a browser search or learned about it by some other means, but they won’t tell me what is available. I can explicitly name the module to be updated, but the apps won’t tell me what has been updated nor will they update everything in bulk if I want.

So, the basic functionality is there in pip and easy_install but there are features missing that I’d like to see that would make them friendlier and easier to use and on par with CPAN and RubyGems.


回答 4

至少有两个easy_install及其后继pip

There are at least two, easy_install and its successor pip.


回答 5

至少从2014年下半年开始,应该考虑使用conda软件包管理器的Continuum Analytics的Anaconda Python发行版。一键下载即可解决一般人们在使用Python时遇到的大多数严重问题(管理不同的Python版本,更新Python版本,软件包管理,虚拟环境,Windows / Mac兼容性)。

它使您无需更改系统就可以使用Python完成几乎所有您想做的事情。我的下一个首选解决方案是pip + virtualenv,但是您要么必须将virtualenv安装到系统Python中(并且系统Python可能不是您想要的版本),要么从源代码构建。Anaconda只需单击一个按钮即可完成整个过程,并添加了许多其他功能。

As of at least late 2014, Continuum Analytics’ Anaconda Python distribution with the conda package manager should be considered. It solves most of the serious issues people run into with Python in general (managing different Python versions, updating Python versions, package management, virtual environments, Windows/Mac compatibility) in one cohesive download.

It enables you to do pretty much everything you could want to with Python without having to change the system at all. My next preferred solution is pip + virtualenv, but you either have to install virtualenv into your system Python (and your system Python may not be the version you want), or build from source. Anaconda makes this whole process the click of a button, as well as adding a bunch of other features.


回答 6

那将是easy_install


回答 7

它称为setuptools。您可以使用“ easy_install”命令运行它。

您可以在http://pypi.python.org/中找到该目录

It’s called setuptools. You run it with the “easy_install” command.

You can find the directory at http://pypi.python.org/


回答 8

我在这里没有在其他答案中提到MacPortsHomebrew,但是由于我确实在Stack Overflow的其他地方看到了有关相关问题的提及,因此我会自己添加0.02美元,许多人似乎认为MacPorts不仅是一个软件包软件包管理器(到目前为止,它们列出了16311个软件包/端口,2931个匹配“ python”,尽管仅适用于Mac),但也可以作为Python软件包/模块的不错的(也许更好)的软件包管理器:

“ … Mac python开发人员使用什么方法来管理其模块?”

答案

科学

“ Mac(与Linux不同)没有软件包管理器,但是您可以安装几个流行的软件包管理器。Macports …”

我仍在参数是否自己使用MacPorts,但目前我正朝着这个方向发展。

I don’t see either MacPorts or Homebrew mentioned in other answers here, but since I do see them mentioned elsewhere on Stack Overflow for related questions, I’ll add my own US$0.02 that many folks seem to consider MacPorts as not only a package manager for packages in general (as of today they list 16311 packages/ports, 2931 matching “python”, albeit only for Macs), but also as a decent (maybe better) package manager for Python packages/modules:

Question

“…what is the method that Mac python developers use to manage their modules?”

Answers

SciPy

“Macs (unlike Linux) don’t come with a package manager, but there are a couple of popular package managers you can install. Macports…”

I’m still debating on whether or not to use MacPorts myself, but at the moment I’m leaning in that direction.


回答 9

在Windows上,安装http://chocolatey.org/,然后

choco install python

用更新的PATH打开一个新的cmd窗口。接下来,做

choco install pip

之后,您可以

pip install pyside
pip install ipython
...

On Windows install http://chocolatey.org/ then

choco install python

Open a new cmd-window with the updated PATH. Next, do

choco install pip

After that you can

pip install pyside
pip install ipython
...

回答 10

由于此处没有人提到pipenv,因此我想描述一下我的观点,为什么每个人都应该使用它来管理python软件包。

正如@ColonelPanic所提到的,Python包索引以及pipvirtualenv也存在多个问题。

Pipenv使用pip解决了大多数问题,并且还提供了其他功能。

Pipenv功能

Pipenv旨在取代pip和virtualenv,这意味着Pipenv将自动为每个项目创建一个单独的虚拟环境,从而避免不同项目的不同python版本/软件包版本之间发生冲突。

  • 启用真正的确定性构建,同时轻松地仅指定所需内容。
  • 生成并检查文件散列是否存在锁定的依赖关系。
  • 如果pyenv可用,则自动安装所需的Python。
  • 通过查找Pipfile递归自动找到您的项目主页。
  • 如果不存在,则自动生成一个Pipfile。
  • 在标准位置自动创建virtualenv。
  • 卸载/安装软件包时,会自动将软件包添加/删除到Pipfile中。
  • 自动加载.env文件(如果存在)。

如果您以前从事过python项目,您将意识到这些功能使管理软件包变得更加容易。

其他命令

  • check检查安全漏洞,并断言当前环境已满足PEP 508要求。(我认为这是一个很大的功能,尤其是在此之后-PyPi上的恶意软件包
  • graph 将显示安装的依赖关系的依赖关系图。

您可以在此处阅读更多内容-Pipenv

安装

您可以在此处找到安装文档

PS:如果您喜欢处理Python Package 请求,您将很高兴知道pipenv由同一位开发人员Kenneth Reitz

Since no one has mentioned pipenv here, I would like to describe my views why everyone should use it for managing python packages.

As @ColonelPanic mentioned there are several issues with the Python Package Index and with pip and virtualenv also.

Pipenv solves most of the issues with pip and provides additional features also.

Pipenv features

Pipenv is intended to replace pip and virtualenv, which means pipenv will automatically create a separate virtual environment for every project thus avoiding conflicts between different python versions/package versions for different projects.

  • Enables truly deterministic builds, while easily specifying only what you want.
  • Generates and checks file hashes for locked dependencies.
  • Automatically install required Pythons, if pyenv is available.
  • Automatically finds your project home, recursively, by looking for a Pipfile.
  • Automatically generates a Pipfile, if one doesn’t exist.
  • Automatically creates a virtualenv in a standard location.
  • Automatically adds/removes packages to a Pipfile when they are un/installed.
  • Automatically loads .env files, if they exist.

If you have worked on python projects before, you would realize these features make managing packages way easier.

Other Commands

  • check checks for security vulnerabilities and asserts that PEP 508 requirements are being met by the current environment. (which I think is a great feature especially after this – Malicious packages on PyPi)
  • graph will show you a dependency graph, of your installed dependencies.

You can read more about it here – Pipenv.

Installation

You can find the installation documentation here

P.S.: If you liked working with the Python Package requests , you would be pleased to know that pipenv is by the same developer Kenneth Reitz


回答 11

在2019年,诗歌是您想要的软件包和依赖项管理器。

https://github.com/sdispater/poetry#why

它是现代,简单和可靠的。

In 2019 poetry is the package and dependency manager you are looking for.

https://github.com/sdispater/poetry#why

It’s modern, simple and reliable.


回答 12

诗歌是您要寻找的。它负责依赖管理,虚拟环境和运行。

Poetry is what you’re looking for. It takes care of dependency management, virtual environments, running.