144

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

比如要安装 Mechanize,我应该按照 INSTALL.txt 将 Mechanize 文件夹放在 C:\Python24\Lib\site-packages 中,但是运行测试不起作用。有人可以帮助阐明这一点吗?谢谢!

4

12 回答 12

159

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

  1. 安装setuptools

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

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

于 2013-03-25T23:34:12.720 回答
86

适用于 Windows 的较新版本的 Python 带有pip包管理器。(资源)

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

使用它来安装软件包:

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

所以在你的情况下是:

pip.exe install mechanize
于 2014-05-23T15:56:04.470 回答
53

是一个很好的关于如何进入easy_installWindows 的教程。简短的回答:将C:\Python26\Scripts(或您安装的任何 python)添加到您的 PATH 中。

于 2009-09-19T22:40:01.780 回答
22

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

于 2009-09-19T20:54:53.303 回答
19

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

python -m pip install [package-name]
于 2017-01-29T14:19:59.133 回答
12

正如我在别处所写

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

幸运的是,有一个 Python 包管理器,称为Pip。Pip 的灵感来自 Ruby 的 Gem,但缺少一些功能。具有讽刺意味的是,Pip 本身安装起来很复杂。在流行的 64 位 Windows 上安装需要从源代码构建和安装两个包。对于刚接触编程的人来说,这是一个很大的要求。


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

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

于 2012-11-18T23:22:03.113 回答
3

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

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

当没有其他任何意义时,这对我有用。我使用 Python 2.7,但文档表明这也适用于 Python 3.x。

于 2013-07-02T15:53:04.650 回答
1

pip是python的包安装器,先更新,再下载需要的

python -m pip install --upgrade pip

然后:

python -m pip install <package_name>
于 2019-05-10T21:51:44.260 回答
1

通过命令提示符升级 pip(Python 目录)

D:\Python 3.7.2>python -m pip install --upgrade pip

现在您可以安装所需的模块

D:\Python 3.7.2>python -m pip install <<yourModuleName>>
于 2019-08-10T11:59:21.797 回答
0

您也可以只下载并运行 ez_setup.py,尽管 SetupTools 文档不再建议这样做。就在两周前对我来说还不错。

于 2009-09-21T16:40:12.363 回答
0

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

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

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

在此处输入图像描述

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

于 2018-03-03T20:14:43.473 回答
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 可执行文件中。

于 2017-02-09T00:59:47.263 回答