关于pip:如何在Windows上安装python包?

How do I install Python packages on Windows?

我很难设置python包。安装工具中的easyInstall应该可以帮助实现这一点,但它们没有针对python 2.6的可执行文件。

例如,为了安装机械化,我只需要根据install.txt将机械化文件夹放在c:python24libsite包中,但是运行测试不起作用。有人能帮我解释一下吗?谢谢!


公认的答案过时了。因此,首先,与easy_install相比,pip更受欢迎,(为什么使用pip而不是简单安装?)。然后按照这些步骤在Windows上安装pip,这很容易。

  • 安装setuptools

    1
    curl https://bootstrap.pypa.io/ez_setup.py | python
  • 安装pip

    1
    curl https://bootstrap.pypa.io/get-pip.py | python
  • 或者,您可以将路径添加到您的环境中,这样您就可以在任何地方使用pip。它在某个地方就像是C:\Python33\Scripts


  • 更新版本的python for windows附带了pip包管理器。(源)

    pip is already installed if you're using Python 2 >=2.7.9 or Python 3 >=3.4

    使用它安装软件包:

    1
    2
    cd C:\Python\Scripts\
    pip.exe install <package-name>

    所以在你的情况下,应该是:

    1
    pip.exe install mechanize


    这是一个关于如何在Windows上获取easy_install的很好的教程。简短的回答是:在您的路径中添加C:\Python26\Scripts(或者您安装的任何python)。


    安装工具不需要可执行文件。您可以下载源代码,将其解包,遍历到下载的目录,并在命令提示下运行python setup.py install


    从python 2.7开始,默认情况下包含pip。只需通过

    1
    python -m pip install [package-name]


    就像我在别处写的那样

    Packaging in Python is dire. The root cause is that the language ships without a package manager.

    Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby's Gem, but lacks some features. 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.

    所以正确的做法是安装PIP。但是,如果您不介意,Christoph Gohlke为所有Windows平台的流行python包提供二进制文件http://www.lfd.uci.edu/~gohlke/pythonlibs/

    事实上,构建一些Python包需要一个C编译器(如mingw32)和库头作为依赖项。在窗户上这可能是个噩梦,所以记住克里斯托夫·高尔克这个名字。


    我在Windows上安装软件包时遇到问题。找到了解决方案。它在Windows7+中工作。主要是使用WindowsPowerShell的任何东西都应该能够使其正常工作。这可以帮助你开始使用它。

    • 首先,您需要将python安装添加到路径变量中。这应该有帮助。
    • 您需要下载压缩格式的包,您正试图安装和解压缩它。如果是一些奇怪的zip格式,请使用7zip,并且应该提取它。
    • 使用Windows PowerShell导航到用setup.py提取的目录(如果有问题,请使用该目录的链接)
    • 运行命令python setup.py install

    这对我很有用,但其他一切都毫无意义。我使用的是python 2.7,但文档表明,这同样适用于python 3.x。


    正如Blauhirn在预装2.7 PIP后提到的。如果它对您不起作用,可能需要将其添加到路径中。

    但是,如果运行Windows10,则不再需要打开终端来安装模块。打开python也是如此。

    您可以直接在搜索菜单中键入pip install mechanize,选择命令,它将安装:

    enter image description here

    但是,如果出现任何问题,它可能会在您阅读错误之前关闭,但它仍然是一个有用的快捷方式。


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
    Collecting networkx
    c:\python27\lib\site-packages\pip\_vendor
    equests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques
    t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus
    e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve
    rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi
    ngwarning.
      SNIMissingWarning
    c:\python27\lib\site-packages\pip\_vendor
    equests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS
    LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con
    nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.
    readthedocs.io/en/latest/security.html#insecureplatformwarning.
      InsecurePlatformWarning
      Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB)
        100% |################################| 1.3MB 664kB/s
    Collecting decorator>=3.4.0 (from networkx)
      Downloading decorator-4.0.11-py2.py3-none-any.whl
    Installing collected packages: decorator, networkx
    Successfully installed decorator-4.0.11 networkx-1.11
    c:\python27\lib\site-packages\pip\_vendor
    equests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i
    s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade
    to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat
    formwarning.
      InsecurePlatformWarning

    或者将目录放到系统路径中的PIP可执行文件中。


    您也可以下载并运行ez_setup.py,尽管setuptools文档不再建议这样做。就在两周前,我的工作还不错。