distutils 到底是做什么的?
我已阅读文档,但我不明白。
为什么我必须使用 distutils 来安装 python 模块?
为什么我无法将模块保存在 python 路径中?
I have read the documentation but I don't understand.
Why do I have to use distutils to install python modules ?
Why do I just can't save the modules in python path ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必必须使用distutils。您可以手动安装模块,就像您可以手动编译C++库(编译每个实现文件,然后链接.obj文件)或手动安装应用程序(编译,放入其自己的目录,添加启动快捷方式)。它变得乏味且容易出错,因为每项重复性任务都是手动完成的。
此外,我为示例列出的手动步骤非常乐观 - 通常,您想做更多。例如,PyQt 将 .ui-to-.py-compiler 添加到路径中,以便您可以通过命令行调用它。
所以你最终会得到一堆可以自动化的工作。仅此一点就是一个很好的论据。
此外,开发人员还必须编写安装说明。使用 distutils 等,您只需指定您的项目由什么组成(当且仅当您需要它时才指定额外的内容) - 例如,您不需要告诉它将所有内容都放在
site 中的新文件夹中-packages
,因为它已经知道这一点。因此最终,开发者和用户都会更容易。
You don't have to use distutils. You can install modules manually, just like you can compile a C++ library manually (compile every implementation file, then link the .obj files) or install an application manually (compile, put into its own directory, add a shortcut for launching). It just gets tedious and error-prone, as every repetive task done manually.
Moreover, the manual steps I listed for the examples are pretty optimistic - often, you want to do more. For example, PyQt adds the .ui-to-.py-compiler to the path so you can invoke it via command line.
So you end up with a stack of work that could be automated. This alone is a good argument.
Also, the devs would have to write installing instructions. With distutils etc, you only have to specify what your project consists of (and fancy extras if and only if you need it) - for example, you don't need to tell it to put everything in a new folder in
site-packages
, because it already knows this.So in the end, it's easier for developers and for users.
什么 python 模块?要安装 python 包,如果它们存在于 pypi 中,你应该这样做:
如果没有,你应该下载它们 .tar.gz 或其他什么,看看你是否找到 setup.py 并像这样运行它:
或者如果你想安装它在开发模式下(您可以更改包并查看结果,而无需再次安装):
这是分发 python 包(setup.py)的常用方法;这个 setup.py 是调用 disutils 的那个。
总结一下,distutils 是一个 python 包,可帮助开发人员创建一个 python 包安装程序,只需运行命令 setup.py install 即可构建和安装给定的包。
所以基本上 disutils 的作用(我只讲重要的东西):
如果您想了解更多详细信息,请参阅此 http://docs.python.org/library/distutils.html< /a>
what python modules ? for installing python package if they exist in pypi you should do :
if not, you should download them .tar.gz or what so ever and see if you find a setup.py and run it like this :
or if you want to install it in development mode (you can change in package and see the result without installing it again ) :
this is the usual way to distribute python package (the setup.py); and this setup.py is the one that call disutils.
to summarize this distutils is a python package that help developer create a python package installer that will build and install a given package by just running the command setup.py install.
so basically what disutils does (i will sit only important stuff):
if you want more detail see this http://docs.python.org/library/distutils.html
您不必使用 distutils 来让您自己的模块在您自己的机器上运行;将它们保存在您的 python 路径中就足够了。
当您决定发布您的模块供其他人使用时,distutils 为他们提供了一种在他们的计算机上安装您的模块的标准方法。 (“distutils”中的“dist”表示分发,就像将您的软件分发给其他人一样。)
You don't have to use distutils to get your own modules working on your own machine; saving them in your python path is sufficient.
When you decide to publish your modules for other people to use, distutils provides a standard way for them to install your modules on their machines. (The "dist" in "distutils" means distribution, as in distributing your software to others.)