如何在Windows上安装Python包?

问题描述 投票:136回答:10

我很难设置python包。来自SetupTools的EasyInstall应该有帮助,但它们没有Python 2.6的可执行文件。

例如,要安装Mechanize,我应该根据INSTALL.txt将Mechanize文件夹放在C:\ Python24 \ Lib \ site-packages中,但运行测试不起作用。有人可以帮助解释一下吗?谢谢!

python pip
10个回答
154
投票

accepted answer已经过时了。首先,pip优于easy_install,(Why use pip over easy_install?)。然后按照以下步骤在Windows上安装pip,这很容易。

  1. 安装setuptoolscurl https://bootstrap.pypa.io/ez_setup.py | python
  2. 安装pipcurl https://bootstrap.pypa.io/get-pip.py | python
  3. 或者,您可以添加环境路径,以便可以在任何地方使用pip。它就像C:\Python33\Scripts

0
投票

正如Blauhirn在预计2.7点之后所提到的那样。如果它不适合您,则可能需要将其添加到路径中。

但是,如果运行Windows 10,则无需再打开终端即可安装模块。打开Python也是如此。

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

enter image description here

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


0
投票

pip是python的软件包安装程序,首先更新它,然后下载你需要的东西

python -m pip install --upgrade pip

然后:

python -m pip install <package_name>

77
投票

较新版本的Python for Windows附带了pip包管理器。 (source)

如果您使用的是Python 2> = 2.7.9或Python 3> = 3.4,则已经安装了pip

用它来安装包:

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

所以在你的情况下,它是:

pip.exe install mechanize

52
投票

This是一个很好的教程,如何在Windows上获得easy_install。简短的回答:将C:\Python26\Scripts(或您安装的任何python)添加到PATH中。


22
投票

您不需要setuptools的可执行文件。您可以下载源代码,解压缩,遍历到下载的目录并在命令提示符下运行python setup.py install


14
投票

从Python 2.7开始,默认包含pip。只需通过下载您想要的包裹

python -m pip install [package-name]

11
投票

就像我wrote elsewhere

用Python打包是可怕的。根本原因是该语言没有包管理器。

幸运的是,Python有一个包管理器,名为Pip。 Pip的灵感来自Ruby的宝石,但缺乏一些功能。具有讽刺意味的是,Pip本身就是complicated to install。在流行的64位Windows上安装需要从源代码构建和安装两个软件包。对于任何刚接触编程的人来说,这是一个很大的问


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

实际上,构建一些Python包需要C编译器(例如mingw32)和依赖项的库头。这可能是Windows上的噩梦,所以请记住Christoph Gohlke这个名字。


3
投票

我在Windows上安装软件包时遇到问题。找到了解决方案。它适用于Windows7 +。主要是Windows Powershell的任何东西都应该能够使它工作。 This可以帮助您开始使用它。

  • 首先,您需要将python安装添加到PATH变量中。 This应该有所帮助。
  • 您需要以zip格式下载要安装的软件包并解压缩。如果它是一些奇怪的zip格式使用7Zip,它应该被提取。
  • 使用Windows Powershell导航到使用setup.py提取的目录(如果遇到问题,请使用链接)
  • 运行命令python setup.py install

当没有别的意义时,那对我有用。我使用的是Python 2.7,但是文档表明同样适用于Python 3.x.


0
投票

您也可以下载并运行ez_setup.py,尽管SetupTools文档不再建议这样做。最近两周前我的工作很好。


0
投票
PS D:\simcut>  C:\Python27\Scripts\pip.exe install networkx
Collecting networkx
c:\python27\lib\site-packages\pip\_vendor\requests\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\requests\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\requests\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可执行文件中。

© www.soinside.com 2019 - 2024. All rights reserved.