给定Python包的名称,要导入的模块的名称是什么? [英] Given the name of a Python package, what is the name of the module to import?

查看:126
本文介绍了给定Python包的名称,要导入的模块的名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道Python模块名称与easy_install中使用的实际软件包的名称背后的逻辑吗?

Does somebody know the logic behind Python modules names vs the name of the actual package used in easy_install?

一些(在其他例子中)对我来说似乎有些不合逻辑的例子:

A few (amongst others) example that seem a bit unlogical to me:

  • 我们做easy_install mysql-python,但实际上是导入import MySQLdb
  • 我们做easy_install python-memcached,但实际上是导入import memcache(不带尾随d)
  • We do easy_install mysql-python, but the import is in fact import MySQLdb
  • We do easy_install python-memcached, but the import is in fact import memcache (without the trailing d)

我没有找到找到等价物的一致方法.对于某些模块,我花了很多时间才能找到它.我在做什么错了?

I didn't find a consistent way of finding the equivalence. For some modules, it took me a lot of browsing to find it. What am I doing wrong?

推荐答案

遗憾的是,没有疯狂的方法. 程序包索引中的名称与您import的模块名称无关.灾难性地某些软件包共享模块名称.如果同时安装两者,则应用程序将出现偶数破损的情况. ( Ruby也有此问题)

Regrettably, there's no method to the madness. The name in the package index is independent of the module name you import. Disastrously some packages share module names. If you install both, your application will break with even odds. (Ruby has this problem too)

用Python打包通常是可怕的.根本原因是该语言在没有软件包管理器的情况下出厂. Ruby和Nodejs随附功能齐全的软件包管理器Gem和Npm,并培育了以GitHub为中心的共享社区. Npm使发布软件包与安装它们一样容易. Nodejs于2009年问世,已经具有 14k软件包.古老的Python软件包索引列出了24k. Ruby Gems列出了44k个软件包.

Packaging in Python is generally dire. The root cause is that the language ships without a package manager. Ruby and Nodejs ship with full-featured package managers Gem and Npm, and have nurtured sharing communities centred around GitHub. Npm makes publishing packages as easy as installing them. Nodejs arrived 2009 and already has 14k packages. The venerable Python package index lists 24k. Ruby Gems lists 44k packages.

幸运的是,有一个不错的Python软件包管理器,名为 Pip . Pip受到Ruby宝石的启发,但缺少一些重要功能(例如,列出程序包和整体升级).具有讽刺意味的是,Pip本身安装复杂.在流行的64位Windows上进行安装需要从源代码构建和安装两个软件包.对于任何刚接触编程的人来说,这都是一个很大的要求.

Fortunately, there is one decent package manager for Python, called Pip. Pip is inspired by Ruby's Gem, but lacks some vital features (eg. listing packages, and upgrading en mass). Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.

Python的开发人员对此无奈,因为他们是经验丰富的程序员,可以轻松地从源代码进行构建,并且他们将Linux发行版与打包的Python模块一起使用.

Python's devs are ignorant of all this frustration because they are seasoned programmers comfortable building from source, and they use Linux distributions with packaged Python modules.

在Python附带软件包管理器之前,成千上万的开发人员将不必要地浪费时间重新发明轮子.

Until Python ships with a package manager, thousands of developers will needlessly waste time reinventing the wheel.

Python 3解决了很多包装问题. 没有任何适用于Python 3的软件包.

Python 3 solves many problems with packaging. There aren't any packages for Python 3.

这篇关于给定Python包的名称,要导入的模块的名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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