Python 有包/模块管理系统吗? [英] Does Python have a package/module management system?

查看:23
本文介绍了Python 有包/模块管理系统吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 是否有包/模块管理系统,类似于 Ruby 有 ruby​​gems,您可以在其中执行 gem install packagename?

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

安装 Python 模块上,我只看到参考python setup.py install,但这需要你先找到包.

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

推荐答案

近期进展

2014 年 3 月:好消息!Python 3.4 随 Pip 一起提供.Pip 长期以来一直是 Python 的事实上的标准包管理器.你可以像这样安装一个包:

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

哇!这是任何 Python 版本的最佳特性.它使每个人都可以访问社区丰富的图书馆.新手不再因设置难度大而无法使用社区库.

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.

然而,Python 打包体验仍然存在许多明显的挫折.累积起来,它们使 Python 对新手非常不受欢迎.此外,长期的忽视(即从 Python 2.0 到 Python 3.3 的 14 年没有随包管理器一起发布)对社区造成了损害.我在下面描述了两者.

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.

重要的是要了解,虽然有经验的用户能够解决这些问题,但对于 Python 新手来说,它们是重大障碍.事实上,困难和普遍的用户不友好可能会阻止他们中的许多人.

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.

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

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

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

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

  1. https://rubygems.org/gems/rails RubyGems 包 rails 页面
  2. https://www.npmjs.org/package/express 包的 Npm 页面快递
  3. https://pypi.python.org/pypi/simplejson/ PyPI 页面包 simplejson
  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

您会看到 RubyGems 和 Npm 页面都以包的单行描述开头,然后是如何安装它的大型友好说明.

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.

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

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..

当然,这一切都是错误的.安装包的最简单方法是使用 Pip 命令.但 PyPI 甚至没有提到 Pip.相反,它引导他们走上了一条陈旧而乏味的道路.

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.

Numpy 是 Python 最受欢迎的库之一.尝试用 Pip 安装它,你会得到这个神秘的错误信息:

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

错误:无法找到 vcvarsall.bat

Error: Unable to find vcvarsall.bat

试图解决 Stack Overflow 上最受欢迎的问题之一:error: 无法找到 vcvarsall.bat"

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

很少有人成功.

为了进行比较,在相同的情况下,Ruby 会打印此消息,其中解释了正在发生的事情以及如何修复它:

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

请更新您的 PATH 以包含构建工具或从 http://rubyinstaller.org/downloads 下载 DevKit并按照 http://github.com/oneclick/rubyinstaller/wiki/Development-套件

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

发布包很困难

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

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.

面对其包含电池"的座右铭,Python 发布时没有包管理器,直到2014 年.

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

在 Pip 之前,事实上的标准是命令 easy_install.这是严重不足的.没有卸载软件包的命令.

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

Pip 是一个巨大的进步.它具有 Ruby's Gem 的大部分功能.不幸的是,具有讽刺意味的是,Pip 直到最近都难以安装.事实上,这个问题仍然是 Stack Overflow 上 Python 的热门问题:How do I install pip在 Windows 上?"

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?"

这篇关于Python 有包/模块管理系统吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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