如何在Windows上安装Python包?

时间:2009-09-19 20:52:59

标签: python pip

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

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

12 个答案:

答案 0 :(得分:155)

accepted answer已过时。首先,pip优先于easy_install,(Why use 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. 或者,您可以添加环境路径,以便在任何地方使用pip。它就像C:\Python33\Scripts

答案 1 :(得分:78)

较新版本的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

答案 2 :(得分:52)

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

答案 3 :(得分:22)

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

答案 4 :(得分:14)

从Python 2.7开始,默认包含pip。只需通过

下载所需的包裹即可
Step 1)  Utility u = new Utility();
Step 2)  u.doSomething();
Step 3)  u = null;

答案 5 :(得分:11)

正如我wrote elsewhere

  

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

     

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


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

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

答案 6 :(得分: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.

答案 7 :(得分:0)

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

答案 8 :(得分: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可执行文件中。

答案 9 :(得分:0)

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

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

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

enter image description here

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

答案 10 :(得分:0)

pip是python的软件包安装程序,请先对其进行更新,然后再下载所需的内容

python -m pip install --upgrade pip

然后:

python -m pip install <package_name>

答案 11 :(得分:0)

  

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

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

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

D:\Python 3.7.2>python -m pip install <<yourModuleName>>
相关问题