Python packages installation in Windows

前端 未结 2 1598
清歌不尽
清歌不尽 2020-12-15 08:18

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

I understand that the official way of installing packages

相关标签:
2条回答
  • 2020-12-15 08:27

    I use pip, and not on Windows, so I can't provide comparison with the Windows-installer option, just some information about 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 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.

    0 讨论(0)
  • 2020-12-15 08:32

    I use windows and python. It is somewhat frustrating, because pip doesn't always work to install things. Python is moving to pip, so I still use it. Pip is nice, because you can uninstall items and use

    pip freeze > requirements.txt
    pip install -r requirements.txt
    

    Another reason I like pip is for virtual environments like venv with python 3.4. I have found venv a lot easier to use on windows than virtualenv.

    If you cannot install a package you have to find the binary for it. http://www.lfd.uci.edu/~gohlke/pythonlibs/

    I have found these binaries to be very useful.

    Pip is trying to make something called a wheel for binary installations.

    pip install wheel
    wheel convert path\to\binary.exe
    pip install converted_wheel.whl
    

    You will also have to do this for any required libraries that do not install and are required for that package.

    0 讨论(0)
提交回复
热议问题