Windows中的Python软件包安装 [英] Python packages installation in Windows

查看:77
本文介绍了Windows中的Python软件包安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习Python,对于软件包的分发和安装方式我有些困惑.

I recently began learning Python, and I am a bit confused about how packages are distributed and installed.

我了解官方安装软件包的方法是 distutils :下载源tarball,解压缩并运行:python setup.py install,然后该模块将自动安装自身

I understand that the official way of installing packages is distutils: you download the source tarball, unpack it, and run: python setup.py install, then the module will automagically install itself

我也了解辅助脚本随附的 setuptools .它使用 eggs 进行分发,据我了解,它是基于distutils构建的,并且执行与上述相同的操作,此外,它还处理了所需的所有依赖项,所有这些依赖项都是从PyPi获取的

I also know about setuptools which comes with easy_install helper script. It uses eggs for distribution, and from what I understand, is built on top of distutils and does the same thing as above, plus it takes care of any dependencies required, all fetched from PyPi

然后还有 pip ,我仍然不确定该点与其他点的区别.

Then there is also pip, which I'm still not sure how it differ from the others.

最后,就像我在Windows计算机上一样,很多软件包还通过 windows安装程序提供了二进制版本,尤其是那些需要编译C/Fortran代码的软件包,否则将是一场噩梦.在Windows上手动编译(假设您具有MSVC或MinGW/Cygwin开发环境,并具有所有必需的库设置.尽管如此,请尝试自己构建numpy或scipy,您将理解!)

Finally, as I am on a windows machine, a lot of packages also offers binary builds through a windows installer, especially the ones that requires compiling C/Fortran code, which otherwise would be a nightmare to manually compile on windows (assumes you have MSVC or MinGW/Cygwin dev environment with all necessary libraries setup.. nonetheless try to build numpy or scipy yourself and you will understand!)

因此有人可以帮助我理解所有这一切,并解释每种方法的优缺点.我想知道每个人如何跟踪软件包(Windows注册表,配置文件等).特别是,您将如何管理所有第三方库(能够列出已安装的软件包,禁用/卸载等).

So can someone help me make sense of all this, and explain the differences, pros/cons of each method. I'd like to know how each keeps track of packages (Windows Registry, config files, ..). In particular, how would you manage all your third-party libraries (be able to list installed packages, disable/uninstall, etc..)

推荐答案

我使用的是pip,而不是Windows,因此我无法与Windows-installer选项进行比较,仅提供有关pip的一些信息:

I use pip, and not on Windows, so I can't provide comparison with the Windows-installer option, just some information about pip:

  • Pip是建立在setuptools之上的,并且需要安装它.
  • Pip是setuptools的easy_install的替代(改进).它完成了easy_install的所有工作,以及更多的功能(确保在实际安装任何所需发行版之前都可以下载所有所需的发行版,以避免损坏的安装,列出已安装的发行版和版本,卸载,搜索PyPI,从列出多个发行版的需求文件中进行安装以及版本...).
  • Pip当前不支持安装任何形式的预编译或二进制发行版,因此,只有在您具有适当的编译器可用的情况下,才能安装带有需要编译扩展名的任何发行版.支持从Windows二进制安装程序进行安装的路线图,但尚不清楚何时会发生.
  • 直到最近,pip的Windows支持还不稳定且未经测试.由于Dave Abrahams的大量工作,pip trunk现在可以在Windows上通过所有测试(并且有一个持续集成服务器帮助我们确保它保持这种状态),但是尚未发布包含该工作的版本.因此,下一个版本应该会提供更可靠的Windows支持.
  • 所有标准的Python软件包安装机制都将有关已安装发行版的所有元数据存储在实际已安装软件包旁边的一个或多个文件中. Distutils使用distribution_name-X.X-pyX.X.egg-info文件,pip使用名称相似的目录,其中包含多个元数据文件. Easy_install将发行版的所有已安装Python代码放入其自己的zipfile或目录中,并将EGG-INFO目录放入该目录中并包含元数据.如果从交互式提示中导入Python软件包,请检查package .__ file__;的值.您应该在附近找到该软件包分发的元数据.
  • 有关已安装发行版的信息仅通过特定于操作系统的打包工具(例如Windows安装程序,Apt或RPM)存储在任何类型的全局注册表中.标准的Python打包工具不会修改或关注这些清单.
  • Pip(或我认为是任何Python打包工具)最好与 virtualenv 一起使用,它允许您创建隔离的按项目的Python迷你环境,您可以在其中安装软件包,而不会影响整个系统.每个新的virtualenv都自动安装了pip.
  • Pip is built on top of setuptools, and requires it to be installed.
  • Pip is a replacement (improvement) for setuptools' easy_install. It does everything easy_install does, plus a lot more (make sure all desired distributions can be downloaded before actually installing any of them to avoid broken installs, list installed distributions and versions, uninstall, search PyPI, install from a requirements file listing multiple distributions and versions...).
  • Pip currently does not support installing any form of precompiled or binary distributions, so any distributions with extensions requiring compilation can only be installed if you have the appropriate compiler available. Supporting installation from Windows binary installers is on the roadmap, but it's not clear when it will happen.
  • Until recently, pip's Windows support was flaky and untested. Thanks to a lot of work from Dave Abrahams, pip trunk now passes all its tests on Windows (and there's a continuous integration server helping us ensure it stays that way), but a release has not yet been made including that work. So more reliable Windows support should be coming with the next release.
  • All the standard Python package installation mechanisms store all metadata about installed distributions in a file or files next to the actual installed package(s). Distutils uses a distribution_name-X.X-pyX.X.egg-info file, pip uses a similarly-named directory with multiple metadata files in it. Easy_install puts all the installed Python code for a distribution inside its own zipfile or directory, and places an EGG-INFO directory inside that directory with metadata in it. If you import a Python package from the interactive prompt, check the value of package.__file__; you should find the metadata for that package's distribution nearby.
  • Info about installed distributions is only stored in any kind of global registry by OS-specific packaging tools such as Windows installers, Apt, or RPM. The standard Python packaging tools don't modify or pay attention to these listings.
  • Pip (or, in my opinion, any Python packaging tool) is best used with virtualenv, which allows you to create isolated per-project Python mini-environments into which you can install packages without affecting your overall system. Every new virtualenv automatically comes with pip installed in it.

您可能还需要了解几个其他项目(是的,还有更多!):

A couple other projects you may want to be aware of as well (yes, there's more!):

  • distribute 是setuptools的一个分支,它具有一些其他的错误修复和功能.
  • distutils2 旨在成为Python打包的下一代". (希望)采用distutils/setuptools/distribute/pip的最佳功能.它是独立开发的,尚无法使用,但最终应替换Python标准库中的distutils,并成为事实上的Python打包解决方案.
  • distribute is a fork of setuptools which has some additional bugfixes and features.
  • distutils2 is intended to be the "next generation" of Python packaging. It is (hopefully) adopting the best features of distutils/setuptools/distribute/pip. It is being developed independently and is not ready for use yet, but eventually should replace distutils in the Python standard library and become the de facto Python packaging solution.

希望所有有助于澄清的内容!祝你好运.

Hope all that helped clarify something! Good luck.

这篇关于Windows中的Python软件包安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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