如何在 Windows 上安装 pip? [英] How can I install pip on Windows?

查看:31
本文介绍了如何在 Windows 上安装 pip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pipeasy_install.但是我应该在 Windows 上使用 easy_install 安装 pip 吗?有没有更好的办法?

解决方案

Python 2.7.9+ 和 3.4+

好消息!Python 3.4(2014 年 3 月发布)和 Python 2.7.9(已发布2014 年 12 月)与 Pip 一起发货.这是任何 Python 版本的最佳特性.它使每个人都可以访问社区丰富的图书馆.新手不再因设置的高难度而被排除在使用社区库之外.在与包管理器一起交付时,Python 加入了 RubyNode.js, HaskellPerlGo—几乎所有其他当代语言都拥有大多数开源社区.谢谢你,Python.

如果您发现在使用 Python 3.4+ 或 Python 2.7.9+ 时 pip 不可用,只需执行例如:

py -3 -m ensurepip

当然,这并不意味着 Python 打包问题就解决了.这种经历仍然令人沮丧.我在堆栈溢出问题中讨论了这个Python 有包/模块管理系统吗?.

而且,对于使用 Python 2.7.8 或更早版本(社区的相当大一部分)的每个人来说,唉.没有计划将 Pip 运送给您.遵循手动说明.

Python 2 ≤ 2.7.8 和 Python 3 ≤ 3.3

面对其'包含电池'的座右铭,Python 没有包管理器.更糟糕的是,Pip 直到最近——具有讽刺意味的是难以安装.

官方说明

根据 https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:

下载get-pip.py,小心将其保存为 .py 文件而不是 .txt.然后,从命令提示符运行它:

python get-pip.py

您可能需要管理员命令提示符才能执行此操作.按照以管理员身份启动命令提示符 (Microsoft TechNet).

这将安装 pip 包,它(在 Windows 中)包含 ...Scriptspip.exe 该路径必须在 PATH 环境变量中才能从命令行使用 pip(请参阅替代说明"的第二部分以了解将其添加到您的路径中,

替代说明

官方文档告诉用户从源代码安装 Pip 及其每个依赖项.这对有经验的人来说很乏味,对新手来说太难了.

为了我们,Christoph Gohlke 为流行的 Python 包准备了 Windows 安装程序 (.msi).他为所有 Python 版本(32 位和 64 位)构建安装程序.您需要:

  1. 安装安装工具
  2. 安装pip

对我来说,这将 Pip 安装在 C:Python27Scriptspip.exe.在您的计算机上找到 pip.exe,然后将其文件夹(例如,C:Python27Scripts)添加到您的路径(启动/编辑环境变量).现在您应该能够从命令行运行 pip.尝试安装软件包:

pip install httpie

就这样(希望如此)!常见问题的解决方法如下:

代理问题

如果您在办公室工作,您可能会使用 HTTP 代理.如果是这样,请设置环境变量 http_proxyhttps_proxy.大多数 Python 应用程序(和其他免费软件)都尊重这些.示例语法:

http://proxy_url:porthttp://用户名:密码@proxy_url:端口

如果您真的不走运,您的代理可能是 Microsoft NTLM 代理.自由软件无法应对.唯一的解决方案是安装一个免费的软件友好代理,转发到讨厌的代理.http://cntlm.sourceforge.net/

无法找到 vcvarsall.bat

Python 模块可以部分用 C 或 C++ 编写.Pip 尝试从源代码编译.如果您没有安装和配置 C/C++ 编译器,您将看到这条神秘的错误消息.

<块引用>

错误:无法找到 vcvarsall.bat

您可以通过安装 C++ 编译器来解决这个问题,例如 MinGW 或 Visual C++.微软实际上提供了一个专门用于 Python 的.或者尝试Microsoft Visual C++ Compiler for Python 2.7.

虽然通常更容易查看Christoph 的网站 以获取您的包裹.>

pip is a replacement for easy_install. But should I install pip using easy_install on Windows? Is there a better way?

解决方案

Python 2.7.9+ and 3.4+

Good news! Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip. This is the best feature of any Python release. It makes the community's wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Node.js, Haskell, Perl, Go—almost every other contemporary language with a majority open-source community. Thank you, Python.

If you do find that pip is not available when using Python 3.4+ or Python 2.7.9+, simply execute e.g.:

py -3 -m ensurepip

Of course, that doesn't mean Python packaging is problem solved. The experience remains frustrating. I discuss this in the Stack Overflow question Does Python have a package/module management system?.

And, alas for everyone using Python 2.7.8 or earlier (a sizable portion of the community). There's no plan to ship Pip to you. Manual instructions follow.

Python 2 ≤ 2.7.8 and Python 3 ≤ 3.3

Flying in the face of its 'batteries included' motto, Python ships without a package manager. To make matters worse, Pip was—until recently—ironically difficult to install.

Official instructions

Per https://pip.pypa.io/en/stable/installing/#do-i-need-to-install-pip:

Download get-pip.py, being careful to save it as a .py file rather than .txt. Then, run it from the command prompt:

python get-pip.py

You possibly need an administrator command prompt to do this. Follow Start a Command Prompt as an Administrator (Microsoft TechNet).

This installs the pip package, which (in Windows) contains ...Scriptspip.exe that path must be in PATH environment variable to use pip from the command line (see the second part of 'Alternative Instructions' for adding it to your PATH,

Alternative instructions

The official documentation tells users to install Pip and each of its dependencies from source. That's tedious for the experienced and prohibitively difficult for newbies.

For our sake, Christoph Gohlke prepares Windows installers (.msi) for popular Python packages. He builds installers for all Python versions, both 32 and 64 bit. You need to:

  1. Install setuptools
  2. Install pip

For me, this installed Pip at C:Python27Scriptspip.exe. Find pip.exe on your computer, then add its folder (for example, C:Python27Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:

pip install httpie

There you go (hopefully)! Solutions for common problems are given below:

Proxy problems

If you work in an office, you might be behind an HTTP proxy. If so, set the environment variables http_proxy and https_proxy. Most Python applications (and other free software) respect these. Example syntax:

http://proxy_url:port
http://username:password@proxy_url:port

If you're really unlucky, your proxy might be a Microsoft NTLM proxy. Free software can't cope. The only solution is to install a free software friendly proxy that forwards to the nasty proxy. http://cntlm.sourceforge.net/

Unable to find vcvarsall.bat

Python modules can be partly written in C or C++. Pip tries to compile from source. If you don't have a C/C++ compiler installed and configured, you'll see this cryptic error message.

Error: Unable to find vcvarsall.bat

You can fix that by installing a C++ compiler such as MinGW or Visual C++. Microsoft actually ships one specifically for use with Python. Or try Microsoft Visual C++ Compiler for Python 2.7.

Often though it's easier to check Christoph's site for your package.

这篇关于如何在 Windows 上安装 pip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆