我如何在Windows上安装Python包?

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

例如要安装Mechanize,我只是应该根据INSTALL.txt将Mechanize文件夹放在C:\ Python24 \ Lib \ site-packages中,但是运行testing不起作用。 有人可以帮助解决这个问题吗? 谢谢!

被接受的答案已经过时。 所以首先, pip优于easy_install ,( 为什么使用pip over easy_install? )。 然后按照这些步骤在Windows上安装pip ,这很容易。

  1. 安装setuptools

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

     curl https://bootstrap.pypa.io/get-pip.py | python 
  3. 或者,您可以将path添加到您的环境中,以便在任何地方使用pip 。 它就像C:\Python33\Scripts

更新版本的Python for Windows附带了pip软件包pipe理器。 (资源)

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

使用它来安装软件包:

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

所以你的情况是:

 pip.exe install mechanize 

这是一个关于如何在Windows上获得easy_install的好教程。 简短的回答:将C:\Python26\Scripts (或者你已经安装的任何python)添加到你的PATH中。

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

正如我在别处写的

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

幸运的是,Python有一个包pipe理器叫做Pip 。 Pip的灵感来自于Ruby的Gem,但缺乏一些function。 讽刺的是,皮普本身安装起来很复杂 。 在stream行的64位Windows上安装要求从源代码构build和安装两个包。 这对于任何新编程的人来说都是一个很大的要求。


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

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

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

 python -m pip install [package-name] 

我在Windows上安装软件包时遇到问题。 find解决scheme。 它在Windows7 +中工作。 主要是Windows Powershell的任何应该能够使其工作。 这可以帮助您开始使用它。

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

这对我来说没有任何意义。 我使用Python 2.7,但是文档build议同样适用于Python 3.x。

您也可以下载并运行ez_setup.py,但SetupTools文档不再提示这一点。 最近2周前为我工作得很好。

 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 

或者把目录放到你系统path中的pip可执行文件中。