2017-03-09 102 views
1

当我在setup.py文件的install_requires条目中列出依赖关系时,如何指定为了安装给定包,必须将其他名称传递给pip包裹名字?Python包名称与setup.py中的pip名称

例如,我可以使用pip来安装pyinterval from PyPI,然后我可以在我的代码中使用from interval import interval, inf, imath或类似的代码。有没有办法告诉SetupTools pyinterval实体“提供”interval包或什么?

编辑:我找到了packaging glossary,这为我澄清了“分发包”和“导入包”之间的术语差异。在我的情况下,pyinterval是分发包,它提供了interval导入包。

+0

相关:http://stackoverflow.com/questions/27308293/how-to-install-python-package-with-a-different-name-using-pip。 PyPI上的'django-emoji'和'emoji'都提供了一个'emoji'包来导入,就像PyPI中的'pyinterval'和'interval'一样,它们都提供了一个'interval'包来导入。 –

回答

0

您不需要告诉setuptools每个依赖项提供的“命令”是什么。您只需按名称安装软件包即pyinterval。您需要知道哪个软件包提供了哪个“命令”,在这种情况下,pyinterval软件包提供的interval'命令'实际上是一个入口点(如以下段落所述)。

这是关于包注册其它软件包可以查询,通常是通过进入点达到使用按键功能,您可以在下面的链接作为一个例子阅读更多关于它: http://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/creation.html#entry-points

综上所述只是告诉这包你的图书馆将需要setuptools的,你可以在GitHub上找到很多例子:

https://github.com/search?l=Python&o=asc&p=6&q=install_requires&ref=searchresults&s=indexed&type=Code&utf8=%E2%9C%93

检查例如瓶的: https://github.com/pallets/flask/blob/master/setup.py

+0

我不清楚你使用的“软件包”的含义。在我的例子中,包是'pyinterval'还是'interval'?许多来源(例如http://www.learnpython.org/en/Modules_and_Packages)似乎将它混淆至少意味着2种不同的东西:https://pypi.python.org/pypi说'pip install package',或者PyPI中的对象,或者包含我们可以使用'import'加载的代码的目录。 –

+0

我更新了答案,以澄清在你的情况下,软件包是'pyinterval'。 'interval'是'pyinterval'包提供的入口点。软件包如您提供的链接(http://www.learnpython.org/en/Modules_and_Packages)中详细介绍的那样,带有扭曲的目录。 pip安装一个包的过程是从PyPI(一个压缩目录)中取出一个包并执行它的'setup.py'。您可以在这里阅读更多信息:https://pip.pypa.io/en/latest/reference/pip_install/#overview –

+0

感谢您的澄清。也许我的一些疑惑是,在PyCharm中,如果我的'install_requires'条目中有'pyinterval',并且我的一个代码文件有'from interval import interval',它仍然会抱怨'Package'interval'没有列出项目要求“。所以我认为我做错了,但也许这只是PyCharm中的一个错误,没有注意到它已经满足了。 –