如何在 Windows 上安装 pip?

发布于 2024-10-13 05:22:15 字数 283 浏览 4 评论 0 原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

被你宠の有点坏 2024-10-20 05:22:15

Python 3.4+ 和 2.7.9+

好消息! Python 3.4(2014 年 3 月发布)和 Python 2.7.9(已发布2014 年 12 月)与 Pip 一起发货。这是所有 Python 版本中最好的功能。它使每个人都可以访问社区丰富的图书馆。新手不再因为设置困难而无法使用社区库。在与包管理器一起发布时,Python 加入了 RubyNode.jsHaskellPerlGo — 几乎所有其他当代语言,拥有大多数开源社区。谢谢你,Python。

如果您发现 pip 不可用,只需运行 ensurepip

  • 在 Windows 上:

    <前><代码>py -3 -m Ensurepip

  • 否则:

    python3 -m Ensurepip
    

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

Python 3 ≤ 3.3 和 2 ≤ 2.7.8

违背其“包含电池”座右铭, Python 出厂时没有包管理器。更糟糕的是,直到最近,Pip 的安装都极其困难。

官方说明

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

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

python get-pip.py

您可能需要管理员命令提示符才能执行此操作。按照以管理员身份启动命令提示符< /a>(微软 TechNet)。

这将安装 pip 包,其中(在 Windows 中)包含 ...\Scripts\pip.exe,该路径必须位于 PATH 环境变量中才能从命令行使用 pip(请参阅“替代说明”的第二部分,将其添加到你的路径,

替代说明

官方文档告诉用户从源代码安装 Pip 及其每个依赖项,这对于经验丰富的人来说是乏味的,而对于新手来说则非常困难,

Christoph Gohlke 准备了 Windows 安装程序(.msi) 对于流行的 Python 软件包,他为所有 Python 版本(32 位和 64 位)构建安装程序

  1. 。 rel="noreferrer">安装 setuptools
  2. 安装 pip

对于我,这将 Pip 安装在 C:\Python27\Scripts\pip.exe 中,在您的计算机上找到 pip.exe,然后添加其文件夹(例如 ) C:\Python27\Scripts) 到您的路径(开始/编辑环境变量)。现在您应该能够从命令行运行pip。尝试安装一个包:

pip install httpie

你就可以了(希望如此)!下面给出了常见问题的解决方案:

代理问题

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

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

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

找不到 vcvarsall.bat

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

错误:无法找到 vcvarsall.bat

您可以通过安装 C++ 编译器 例如 MinGWVisual C++。微软实际上发布了一个专门用于 Python 的工具。或者尝试适用于 Python 2.7 的 Microsoft Visual C++ 编译器

通常,在 Christoph 的网站 查找您的软件包会更容易。

Python 3.4+ and 2.7.9+

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, simply run ensurepip.

  • On Windows:

    py -3 -m ensurepip
    
  • Otherwise:

    python3 -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?.

Python 3 ≤ 3.3 and 2 ≤ 2.7.8

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 ...\Scripts\pip.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:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (for example, C:\Python27\Scripts) 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.

薔薇婲 2024-10-20 05:22:15

-- 过时 -- 使用分发,而不是此处描述的 setuptools。 --
-- 过时的 #2 -- 使用 setuptools,因为分发已被弃用。

正如您提到的,pip 不包含独立的安装程序,但您可以使用其前身 easy_install 来安装它。

所以:

  1. 从这里下载最后一个 pip 版本: http://pypi.python.org/pypi/pip #downloads
  2. 解压
  3. 下载最后一个适用于 Windows 的简易安装程序:(下载 http://pypi.python.org/pypi/setuptools )。安装它。
  4. 将未压缩的 pip 文件夹 content 复制到 C:\Python2x\ 文件夹中(不要将整个文件夹复制到其中,仅复制内容),因为 python 命令不起作用在 C:\Python2x 文件夹之外,然后运行: python setup.py install
  5. 路径

将 python C:\Python2x\Scripts 添加到您所在的 完毕。

现在您可以使用 pip install package 轻松安装软件包,就像在 Linux 中一样:)

-- Outdated -- use distribute, not setuptools as described here. --
-- Outdated #2 -- use setuptools as distribute is deprecated.

As you mentioned pip doesn't include an independent installer, but you can install it with its predecessor easy_install.

So:

  1. Download the last pip version from here: http://pypi.python.org/pypi/pip#downloads
  2. Uncompress it
  3. Download the last easy installer for Windows: (download the .exe at the bottom of http://pypi.python.org/pypi/setuptools ). Install it.
  4. copy the uncompressed pip folder content into C:\Python2x\ folder (don't copy the whole folder into it, just the content), because python command doesn't work outside C:\Python2x folder and then run: python setup.py install
  5. Add your python C:\Python2x\Scripts to the path

You are done.

Now you can use pip install package to easily install packages as in Linux :)

鲸落 2024-10-20 05:22:15

2014 更新:

1) 如果您安装了 Python 3.4 或更高版本,pip 包含在 Python 中并且应该已经可以在您的系统上运行。

2) 如果您运行的是 Python 3.4 以下的版本,或者由于某种原因 pip 没有随 Python 3.4 一起安装,那么您可能会使用 pip 的官方安装脚本 get-pip.py。 pip 安装程序现在为您获取 setuptools,并且无论架构如何(32 位或 64 位)都可以工作。

安装此处详细说明并涉及:

要安装或升级 pip,请安全下载 get-pip。 py

然后运行以下命令(可能需要管理员访问权限):

python get-pip.py

要升级现有的 setuptools(或分发),请运行 pip install -U setuptools

我将把下面两组旧指令留给后代。

旧答案:

对于 64 位版本的 Windows 版本 - 由于 ez_setup,64 位 Windows + Python 过去需要单独的安装方法,但我已经测试了新的在运行 32 位 Python 和 64 位 Python 的 64 位 Windows 上使用分发方法,现在您可以对所有版本的 Windows/Python 2.7X 使用相同的方法:

旧方法 2 使用 分发

  1. 下载 分发 - 我把我的放在 C:\Python27\Scripts 中(如果 Scripts 目录不存在,请随意创建它。
  2. 打开启动命令提示符(在 Windows 上,如果您不使用,您应该查看 conemu2 PowerShell)并更改 (cd) 到您已下载的目录distribute_setup.py 到。
  3. 运行distribute_setup:python allocate_setup.py(如果你的python安装目录没有添加到你的路径中,这将不起作用 - 转到此处寻求帮助
  4. 将当前目录更改为 Python 安装的 Scripts 目录 (C:\Python27\Scripts) 或添加该目录,如下所示以及 Python 基本安装目录到您的 %PATH% 环境变量中。
  5. 使用新安装的 setuptools 安装 pip: easy_install pip

除非您位于 easy_install.exe 所在的目录 (C:\Python27\脚本将是 Python 2.7 的默认目录),或者您已将该目录添加到您的路径中。

旧方法 1 使用 ez_setup:

来自 setuptools 页面 --

下载ez_setup.py并运行;它将下载适当的 .egg 文件并为您安装。 (目前,由于 distutils 安装程序兼容性问题,提供的 .exe 安装程序不支持 Windows 64 位版本的 Python。

之后,您可以继续:

  1. 添加 c:\Python2x\Scripts到 Windows 路径(将 Python2x 中的 x 替换为您已安装的实际版本号)
  2. 打开一个新的 (!) DOS 提示符,然后运行 ​​easy_install pip。

2014 UPDATE:

1) If you have installed Python 3.4 or later, pip is included with Python and should already be working on your system.

2) If you are running a version below Python 3.4 or if pip was not installed with Python 3.4 for some reason, then you'd probably use pip's official installation script get-pip.py. The pip installer now grabs setuptools for you, and works regardless of architecture (32-bit or 64-bit).

The installation instructions are detailed here and involve:

To install or upgrade pip, securely download get-pip.py.

Then run the following (which may require administrator access):

python get-pip.py

To upgrade an existing setuptools (or distribute), run pip install -U setuptools

I'll leave the two sets of old instructions below for posterity.

OLD Answers:

For Windows editions of the 64 bit variety - 64-bit Windows + Python used to require a separate installation method due to ez_setup, but I've tested the new distribute method on 64-bit Windows running 32-bit Python and 64-bit Python, and you can now use the same method for all versions of Windows/Python 2.7X:

OLD Method 2 using distribute:

  1. Download distribute - I threw mine in C:\Python27\Scripts (feel free to create a Scripts directory if it doesn't exist.
  2. Open up a command prompt (on Windows you should check out conemu2 if you don't use PowerShell) and change (cd) to the directory you've downloaded distribute_setup.py to.
  3. Run distribute_setup: python distribute_setup.py (This will not work if your python installation directory is not added to your path - go here for help)
  4. Change the current directory to the Scripts directory for your Python installation (C:\Python27\Scripts) or add that directory, as well as the Python base installation directory to your %PATH% environment variable.
  5. Install pip using the newly installed setuptools: easy_install pip

The last step will not work unless you're either in the directory easy_install.exe is located in (C:\Python27\Scripts would be the default for Python 2.7), or you have that directory added to your path.

OLD Method 1 using ez_setup:

from the setuptools page --

Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue.

After this, you may continue with:

  1. Add c:\Python2x\Scripts to the Windows path (replace the x in Python2x with the actual version number you have installed)
  2. Open a new (!) DOS prompt. From there run easy_install pip
谁许谁一生繁华 2024-10-20 05:22:15

2016+ 更新:

这些答案已经过时或冗长且困难。

如果您使用的是 Python 3.4+ 或 2.7.9+,则为 Windows 上默认安装。否则,简而言之:

  1. 下载 pip 安装程序:
    https://bootstrap.pypa.io/get-pip.py
  2. 如果偏执,请检查文件以确认它不是恶意的
    (必须 b64 解码)。
  3. 以管理员身份打开下载文件夹中的控制台并运行
    get-pip.py。或者,在资源管理器中右键单击其图标并选择“以管理员身份运行...”。

新的二进制文件 pip.exe(以及已弃用的 easy_install.exe)将位于 "%ProgramFiles%\PythonXX\Scripts" 文件夹中(或类似的),通常不在您的 PATH 变量中。我建议添加它。

2016+ Update:

These answers are outdated or otherwise wordy and difficult.

If you've got Python 3.4+ or 2.7.9+, it will be installed by default on Windows. Otherwise, in short:

  1. Download the pip installer:
    https://bootstrap.pypa.io/get-pip.py
  2. If paranoid, inspect file to confirm it isn't malicious
    (must b64 decode).
  3. Open a console in the download folder as Admin and run
    get-pip.py. Alternatively, right-click its icon in Explorer and choose the "run as Admin...".

The new binaries pip.exe (and the deprecated easy_install.exe) will be found in the "%ProgramFiles%\PythonXX\Scripts" folder (or similar), which is often not in your PATH variable. I recommend adding it.

打小就很酷 2024-10-20 05:22:15

Python 3.4 于 2014 年 3 月发布,附带 pip
http://docs.python.org/3.4/whatsnew/3.4.html
因此,自从 Python 3.4 发布以来,在 Windows 上安装 pip 的最新方法是仅安装 Python。

推荐的使用方法是将其作为模块调用,尤其是在安装了多个 python 发行版或版本的情况下,以保证包到达正确的位置:
python -m pip install --upgrade packageXYZ

https://docs.python.org/3/installing/#work-with-multiple-versions-of-python-installed-in-parallel

Python 3.4, which was released in March 2014, comes with pip included:
http://docs.python.org/3.4/whatsnew/3.4.html
So, since the release of Python 3.4, the up-to-date way to install pip on Windows is to just install Python.

The recommended way to use it is to call it as a module, especially with multiple python distributions or versions installed, to guarantee packages go to the correct place:
python -m pip install --upgrade packageXYZ

https://docs.python.org/3/installing/#work-with-multiple-versions-of-python-installed-in-parallel

遮云壑 2024-10-20 05:22:15

当我必须使用 Windows 时,我使用 ActivePython,它会自动将所有内容添加到您的 PATH 中,并包含一个名为 PyPM< 的包管理器/a> 提供二进制包管理,使安装包更快更简单。

pipeasy_install 并不完全相同,因此有些东西您可以通过 pip 获得,但不能通过 easy_install 获得代码> 反之亦然

我的建议是您获得 ActivePython Community Edition 并且不用担心获取所有内容的巨大麻烦在 Windows 上为 Python 设置。然后,您可以使用pypm

如果您想使用 pip,您必须检查 ActiveState 安装程序中的 PyPM 选项。安装完成后,您只需注销并再次登录,pip 将在命令行上可用,因为它包含在 ActiveState 安装程序 PyPM 选项中,并且路径已设置安装程序已为您设置。 PyPM 也将可用,但您不必使用它。

When I have to use Windows, I use ActivePython, which automatically adds everything to your PATH and includes a package manager called PyPM which provides binary package management making it faster and simpler to install packages.

pip and easy_install aren't exactly the same thing, so there are some things you can get through pip but not easy_install and vice versa.

My recommendation is that you get ActivePython Community Edition and don't worry about the huge hassle of getting everything set up for Python on Windows. Then, you can just use pypm.

In case you want to use pip you have to check the PyPM option in the ActiveState installer. After installation you only need to logoff and log on again, and pip will be available on the commandline, because it is contained in the ActiveState installer PyPM option and the paths have been set by the installer for you already. PyPM will also be available, but you do not have to use it.

心在旅行 2024-10-20 05:22:15

最新的方法是使用 Windows 的包管理器 Chocolatey

安装完成后,您所要做的就是打开命令提示符并运行以下三个命令,这将安装 Python 2.7、easy_install 和 pip。它将自动检测您使用的是 x64 还是 x86 Windows。

cinst python
cinst easy.install
cinst pip

Chocolatey Gallery 上的所有其他 Python 包都可以在此处找到。

The up-to-date way is to use Windows' package manager Chocolatey.

Once this is installed, all you have to do is open a command prompt and run the following the three commands below, which will install Python 2.7, easy_install and pip. It will automatically detect whether you're on x64 or x86 Windows.

cinst python
cinst easy.install
cinst pip

All of the other Python packages on the Chocolatey Gallery can be found here.

若有似无的小暗淡 2024-10-20 05:22:15

2015 年 3 月更新

Python 2.7.9 及更高版本(在 Python 2 系列上)以及 Python 3.4 及更高版本默认包含 pip,因此您可能已经拥有 pip。

如果不这样做,请在提示符下运行这一行命令(可能需要管理员访问权限):

python -c "exec('try: from urllib2 import urlopen \nexcept: from urllib.request import urlopen');f=urlopen('https://bootstrap.pypa.io/get-pip.py').read();exec(f)"

它将安装 pip 。如果尚未安装 Setuptoolsget-pip.py 将安装它也适合你。

正如评论中提到的,上述命令将从 Pip 源代码存储库下载代码 GitHub,并且在您的环境中动态运行它。因此请注意,这是下载、检查和运行步骤的快捷方式,所有这些都使用 Python 本身的单个命令。如果您信任 Pip,请毫无疑问地继续。

确保您的 Windows 环境变量 PATH 包含 Python 的文件夹(对于 Python 2.7.x 默认安装:C:\Python27C:\Python27\Scripts,对于 Python 3.3x :C:\Python33C:\Python33\Scripts 等)。

Update March 2015

Python 2.7.9 and later (on the Python 2 series), and Python 3.4 and later include pip by default, so you may have pip already.

If you don't, run this one line command on your prompt (which may require administrator access):

python -c "exec('try: from urllib2 import urlopen \nexcept: from urllib.request import urlopen');f=urlopen('https://bootstrap.pypa.io/get-pip.py').read();exec(f)"

It will install pip. If Setuptools is not already installed, get-pip.py will install it for you too.

As mentioned in comments, the above command will download code from the Pip source code repository at GitHub, and dynamically run it at your environment. So be noticed that this is a shortcut of the steps download, inspect and run, all with a single command using Python itself. If you trust Pip, proceed without doubt.

Be sure that your Windows environment variable PATH includes Python's folders (for Python 2.7.x default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, and so on).

思念满溢 2024-10-20 05:22:15

安装程序

我已经为 distributepip 此处(目标是使用 pip ,而无需使用 easy_install 引导或保存并运行Python脚本):

在 Windows 上,只需下载并安装首先从上述链接安装 distribute,然后安装 pip。上面的 distribute 链接确实包含存根 .exe 安装程序,并且这些安装程序目前仅是 32 位。我没有在64位Windows上测试过效果。

在 Windows 上构建

为新版本重做此过程并不困难,我将其包含在此处以供参考。

构建 distribute

为了获取存根 .exe 文件,您需要有一个 Visual C++ 编译器(它显然也可以与 MinGW 编译)

hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist

构建 pip< /代码>

git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist

Installers

I've built Windows installers for both distribute and pip here (the goal being to use pip without having to either bootstrap with easy_install or save and run Python scripts):

On Windows, simply download and install first distribute, then pip from the above links. The distribute link above does contain stub .exe installers, and these are currently 32-bit only. I haven't tested the effect on 64-bit Windows.

Building on Windows

The process to redo this for new versions is not difficult, and I've included it here for reference.

Building distribute

In order to get the stub .exe files, you need to have a Visual C++ compiler (it is apparently compilable with MinGW as well)

hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist

Building pip

git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist
七秒鱼° 2024-10-20 05:22:15

以下适用于 Python 2.7。保存此脚本并启动它:

https://raw.github.com/pypa/pip/master /contrib/get-pip.py

Pip 已安装,然后将路径添加到您的环境:

C:\Python27\Scripts

最后

pip install virtualenv

您还需要 Microsoft Visual C++ 2008 Express 要获得良好的编译器并在安装软件包时避免出现此类消息:

error: Unable to find vcvarsall.bat

如果您有 64 位版本的 Windows 7,您可以阅读64 位 Windows 7 上的 64 位 Python 安装问题安装Python可执行包(注册表项问题)。

The following works for Python 2.7. Save this script and launch it:

https://raw.github.com/pypa/pip/master/contrib/get-pip.py

Pip is installed, then add the path to your environment :

C:\Python27\Scripts

Finally

pip install virtualenv

Also you need Microsoft Visual C++ 2008 Express to get the good compiler and avoid these kind of messages when installing packages:

error: Unable to find vcvarsall.bat

If you have a 64-bit version of Windows 7, you may read 64-bit Python installation issues on 64-bit Windows 7 to successfully install the Python executable package (issue with registry entries).

街角卖回忆 2024-10-20 05:22:15

对于最新的 Python 下载 - 我在 Windows 上有 Python 3.6。你不必怀疑。您需要的一切都在那里。深吸一口气,我将向您展示如何操作。

  1. 确定您安装 Python 的位置。对我来说,它位于以下目录

    “在此处输入图像描述"

    <块引用>

    现在,让我们将 Python 和 pip 添加到环境变量 path 设置中
    如果您使用的是 Windows,则可以在任何地方键入 pippython 进行调用
    来自安装位置的 pythonpip

    因此,可以在上面屏幕的文件夹“SCRIPTS”下找到 PIP
    让我们在环境变量 path 中添加 Python 和 PIP。

    “在此处输入图像描述"

    快完成了。让我们使用 CMD 进行测试,以使用 pip 安装 google 软件包。

     pip install google
    

    “在此处输入图像描述"

For the latest Python download - I have Python 3.6 on Windows. You don't have to wonder. Everything you need is there. Take a breath, and I will show you how to do it.

  1. Make sure where you install Python. For me, it was in the following directory

    Enter image description here

    Now, let’s add the Python and pip into environment variable path settings
    if you are on Windows, so that typing pip or python anywhere call
    python or pip from where they are installed.

    So, PIP is found under the folder in the above screen "SCRIPTS"
    Let's add Python and PIP in the environment variable path.

    Enter image description here

    Almost done. Let's test with CMD to install the google package using pip.

     pip install google
    

    Enter image description here

扭转时空 2024-10-20 05:22:15

正如 Adrián 所说,要在 Python 2.x 上全局安装 pip,easy_install 似乎是最佳解决方案。

但是,pip 的 安装说明 建议使用 virtualenv 因为每个 virtualenv 都会自动安装 pip。这不需要 root 访问权限或修改系统 Python 安装。

不过安装 virtualenv 仍然需要 easy_install 。

2018 更新:

Python 3.3+ 现在包含 venv 模块 用于轻松创建虚拟环境,如下所示:

python3 -m venv /path/to/new/virtual/environment

请参阅有关创建后激活环境的不同平台方法的文档,但通常是以下之一:

$ source <venv>/bin/activate 

C:\> <venv>\Scripts\activate.bat

To install pip globally on Python 2.x, easy_install appears to be the best solution as Adrián states.

However the installation instructions for pip recommend using virtualenv since every virtualenv has pip installed in it automatically. This does not require root access or modify your system Python installation.

Installing virtualenv still requires easy_install though.

2018 update:

Python 3.3+ now includes the venv module for easily creating virtual environments like so:

python3 -m venv /path/to/new/virtual/environment

See documentation for different platform methods of activating the environment after creation, but typically one of:

$ source <venv>/bin/activate 

C:\> <venv>\Scripts\activate.bat
神妖 2024-10-20 05:22:15

要使用 pip,并不强制要求您直接在系统中安装 pip。您可以通过 virtualenv 使用它。您可以执行以下步骤:

我们通常需要为一个特定项目安装 Python 包。因此,现在创建一个项目文件夹,假设为 myproject。

  • virtualenv解压文件夹中复制virtualenv.py文件,并将其粘贴到myproject文件夹中

现在创建一个虚拟环境,假设 >myvirtualenv 如下,在 myproject 文件夹内:

python virtualenv.py myvirtualenv

它将显示:

New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

现在您的虚拟环境 myvirtualenv 已在项目文件夹内创建。您可能会注意到,pip 现在已安装在您的虚拟环境中。您所需要做的就是使用以下命令激活虚拟环境。

myvirtualenv\Scripts\activate

您将在命令提示符处看到以下内容:

(myvirtualenv) PATH\TO\YOUR\PROJECT\FOLDER>pip install package_name

现在您可以开始使用 pip,但请确保您已激活 virtualenv(查看提示符左侧)。

这是在虚拟环境中安装 pip ie 最简单的方法之一,但您需要随身携带 virtualenv.py 文件。

更多安装 pip/virtualenv/virtualenvwrapper 的方法,可以参考 thegauraw.tumblr.com

To use pip, it is not mandatory that you need to install pip in the system directly. You can use it through virtualenv. What you can do is follow these steps:

We normally need to install Python packages for one particular project. So, now create a project folder, let’s say myproject.

  • Copy the virtualenv.py file from the decompressed folder of virtualenv, and paste inside the myproject folder

Now create a virtual environment, let’s say myvirtualenv as follows, inside the myproject folder:

python virtualenv.py myvirtualenv

It will show you:

New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.

Now your virtual environment, myvirtualenv, is created inside your project folder. You might notice, pip is now installed inside you virtual environment. All you need to do is activate the virtual environment with the following command.

myvirtualenv\Scripts\activate

You will see the following at the command prompt:

(myvirtualenv) PATH\TO\YOUR\PROJECT\FOLDER>pip install package_name

Now you can start using pip, but make sure you have activated the virtualenv looking at the left of your prompt.

This is one of the easiest way to install pip i.e. inside virtual environment, but you need to have virtualenv.py file with you.

For more ways to install pip/virtualenv/virtualenvwrapper, you can refer to thegauraw.tumblr.com.

删除会话 2024-10-20 05:22:15

2016 年更新: Pip 应该已包含在 Python 2.7.9+ 或 3.4+ 中,但如果出于某种原因它不存在,您可以使用以下一行。

PS:

  1. 这应该已经满足大多数情况下,但如有必要,请确保您的环境变量 PATH 包含 Python 的文件夹(例如 Windows 默认安装上的 Python 2.7.xC:\Python27 和 C:\Python27\脚本,对于Python 3.3xC:\Python33 和 C:\Python33\Scripts 等)

  2. 我遇到了同样的问题,然后发现了这样的问题最简单的方法(一个衬垫!)在官方网站上提到:http://www.pip-installer.org/en/latest/installing.html pip-installer.org/en/latest/installing.html

不能相信有很多冗长(也许已经过时?)的答案。对他们表示感谢,但是,请为这个简短的答案投票,以帮助更多的新人!

Updated at 2016 : Pip should already be included in Python 2.7.9+ or 3.4+, but if for whatever reason it is not there, you can use the following one-liner.

PS:

  1. This should already be satisfied in most cases but, if necessary, be sure that your environment variable PATH includes Python's folders (for example, Python 2.7.x on Windows default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, etc)

  2. I encounter same problem and then found such perhaps easiest way (one liner!) mentioned on official website here: http://www.pip-installer.org/en/latest/installing.html

Can't believe there are so many lengthy (perhaps outdated?) answers out there. Feeling thankful to them but, please up-vote this short answer to help more new comers!

辞旧 2024-10-20 05:22:15

我只是想为那些在 Windows 64 位安装 setuptools 时遇到问题的人添加一种解决方案。这个问题在 python.org 上的这个 bug 中进行了讨论,并且截至本评论发表之日仍未解决。提到了一个简单的解决方法,并且它可以完美地工作。一项注册表更改对我来说起了作用。

链接: http://bugs.python.org/issue6792#

对我有用的解决方案... :

为 2.6+ 版本的 Python 添加此注册表设置:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

这很可能是您已经拥有的 Python 2.6+ 注册表设置:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

显然,您需要将 2.6 版本替换为您正在运行的任何版本的 Python。

I just wanted to add one more solution for those having issues installing setuptools from Windows 64-bit. The issue is discussed in this bug on python.org and is still unresolved as of the date of this comment. A simple workaround is mentioned and it works flawlessly. One registry change did the trick for me.

Link: http://bugs.python.org/issue6792#

Solution that worked for me...:

Add this registry setting for 2.6+ versions of Python:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

This is most likely the registry setting you will already have for Python 2.6+:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.6\InstallPath]
 @="C:\\Python26\\"

Clearly, you will need to replace the 2.6 version with whatever version of Python you are running.

笨笨の傻瓜 2024-10-20 05:22:15

到目前为止,我发现的最好方法只是两行代码:

curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

它是在 Windows 8 上使用 PowerShell、Cmd 和 Git Bash (MinGW)。

您可能想将路径添加到您的环境中。它位于类似C:\Python33\Scripts 的位置。

The best way I found so far, is just two lines of code:

curl http://python-distribute.org/distribute_setup.py | python
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python

It was tested on Windows 8 with PowerShell, Cmd, and Git Bash (MinGW).

And you probably want to add the path to your environment. It's somewhere like C:\Python33\Scripts.

压抑⊿情绪 2024-10-20 05:22:15

这是如何简单地安装 pip 的方法。

  1. 此内容复制并粘贴到文件中,作为get-pip.py< /强>。
  2. get-pip.py 复制并粘贴到 Python 文件夹中。C:\Python27
  3. 双击 get-pip.py 文件。它将在您的计算机上安装 pip。
  4. 现在您必须将 C:\Python27\Scripts 路径添加到环境变量中。因为它包含 pip.exe 文件。
  5. 现在您可以使用 pip 了。打开 cmd 并输入
    pip install package_name

Here how to install pip the easy way.

  1. Copy and paste this content in a file as get-pip.py.
  2. Copy and paste get-pip.py into the Python folder.C:\Python27.
  3. Double click on get-pip.py file. It will install pip on your computer.
  4. Now you have to add C:\Python27\Scripts path to your environment variable. Because it includes the pip.exe file.
  5. Now you are ready to use pip. Open cmd and type as
    pip install package_name
一梦等七年七年为一梦 2024-10-20 05:22:15

PythonXY 附带了 pip,其中 其他

PythonXY comes with pip included, among others.

沫雨熙 2024-10-20 05:22:15

我在 Windows 上使用来自 Continum.io 的跨平台 Anaconda 包管理器,它很可靠。它具有虚拟环境管理和功能齐全的外壳以及常用实用程序(例如 conda、pip)。

> conda install <package>               # access distributed binaries

> pip install <package>                 # access PyPI packages 

conda 还附带了具有非 Python 依赖项的库的二进制文件,例如 pandasnumpy 等。这在 Windows 上尤其有用,因为它可以很难正确编译 C 依赖项。

I use the cross-platform Anaconda package manager from continuum.io on Windows and it is reliable. It has virtual environment management and a fully featured shell with common utilities (e.g. conda, pip).

> conda install <package>               # access distributed binaries

> pip install <package>                 # access PyPI packages 

conda also comes with binaries for libraries with non-Python dependencies, e.g. pandas, numpy, etc. This proves useful particularly on Windows as it can be hard to correctly compile C dependencies.

玻璃人 2024-10-20 05:22:15

当我按照此处的说明进行操作时,我在以不同方式安装时遇到了一些问题。我认为以同样的方式在每个 Windows 环境中安装是非常棘手的。就我而言,我需要在同一台机器上安装 Python 2.6、2.7 和 3.3 以用于不同的目的,因此我认为存在更多问题。
但以下说明对我来说非常有效,因此可能取决于您的环境,您应该尝试这个:

http://docs.python-guide.org/en/latest/starting/install/win/

另外,由于环境不同,我发现使用虚拟环境非常有用,我有使用不同库的网站,最好将它们封装到一个文件夹中,请查看说明,简要说明如果安装了 PIP,则只需安装 VirtualEnv:

pip install virtualenv

在运行所有文件的文件夹中

virtualenv venv

几秒钟后,您将拥有一个虚拟环境venv 文件夹中的所有内容,要激活它,请运行 venv/Scripts/activate.bat (停用环境很容易,使用 deactivate.bat)。您安装的每个库最终都会位于 venv\Lib\site-packages 中,并且可以轻松地将整个环境移动到某个地方。

我发现的唯一缺点是某些代码编辑器无法识别这种环境,并且您会在代码中看到警告,因为找不到导入的库。当然,有一些棘手的方法可以做到这一点,但编辑者最好记住虚拟环境现在很常见。

希望有帮助。

I had some issues installing in different ways when I followed instructions here. I think it's very tricky to install in every Windows environment in the same way. In my case I need Python 2.6, 2.7 and 3.3 in the same machine for different purposes so that's why I think there're more problems.
But the following instructions worked perfectly for me, so might be depending on your environment you should try this one:

http://docs.python-guide.org/en/latest/starting/install/win/

Also, due to the different environments I found incredible useful to use Virtual Environments, I had websites that use different libraries and it's much better to encapsulate them into a single folder, check out the instructions, briefly if PIP is installed you just install VirtualEnv:

pip install virtualenv

Into the folder you have all your files run

virtualenv venv

And seconds later you have a virtual environment with everything in venv folder, to activate it run venv/Scripts/activate.bat (deactivate the environment is easy, use deactivate.bat). Every library you install will end up in venv\Lib\site-packages and it's easy to move your whole environment somewhere.

The only downside I found is some code editors can't recognize this kind of environments, and you will see warnings in your code because imported libraries are not found. Of course there're tricky ways to do it but it would be nice editors keep in mind Virtual Environments are very normal nowadays.

Hope it helps.

一腔孤↑勇 2024-10-20 05:22:15
  1. 下载脚本: https://raw.github.com/pypa/ pip/master/contrib/get-pip.py
  2. 将其保存在驱动器上的某个位置,例如 C:\pip-script\get-pip.py
  3. 从命令提示符导航到该路径并运行“ python get-pip.py ”

指南链接:http://www.pip-installer.org/ en/latest/installing.html#install-pip

注意:确保像这样的脚本路径 (C:\Python27\Scripts) 也添加到 int %PATH% 环境变量中。

  1. Download script: https://raw.github.com/pypa/pip/master/contrib/get-pip.py
  2. Save it on drive somewhere like C:\pip-script\get-pip.py
  3. Navigate to that path from command prompt and run " python get-pip.py "

Guide link: http://www.pip-installer.org/en/latest/installing.html#install-pip

Note: Make sure scripts path like this (C:\Python27\Scripts) is added int %PATH% environment variable as well.

长梦不多时 2024-10-20 05:22:15

非常简单:(

Step 1: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
Step 2: wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
Step 2: python ez_setup.py
Step 3: python get-pip.py

确保您的 Python 和 Python 脚本目录(例如,C:\Python27C:\Python27\Scripts)位于 PATH 中。)

It's very simple:

Step 1: wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
Step 2: wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
Step 2: python ez_setup.py
Step 3: python get-pip.py

(Make sure your Python and Python script directory (for example, C:\Python27 and C:\Python27\Scripts) are in the PATH.)

窝囊感情。 2024-10-20 05:22:15

自 2014 年 2 月 4 日开始工作:):

如果您尝试通过 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip 正如@Colonel Panic所建议的,您可能已经成功安装了pip包管理器,但您可能无法安装任何带有 pip 的包。您可能也遇到了与我尝试安装 Beautiful Soup 4 时遇到的相同的 SSL 错误如果您查看 pip.log 文件:

Downloading/unpacking beautifulsoup4
  Getting page https://pypi.python.org/simple/beautifulsoup4/
  Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: **connection error: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed**
  Will skip URL https://pypi.python.org/simple/beautifulsoup4/ when looking for download links for beautifulsoup4

问题是旧版本的 OpenSSL 的问题与 pip 1.3.1 及以上版本不兼容。目前最简单的解决方法是安装 pip 1.2.1,它不需要 SSL

: Windows 上的 Pip:

  1. https 下载 pip 1.2.1 ://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
  2. 提取 pip-1.2.1.tar.gz 文件
  3. 将目录更改为提取的文件夹:< code>cd <解压文件夹的路径>/pip-1.2.1
  4. 运行 python setup.py install
  5. 现在确保 C:\Python27\Scripts 是在 PATH 中,因为 pip 安装在 C:\Python27\Scripts 目录中,与通常安装 Python 包的 C:\Python27\Lib\site-packages 目录不同

现在尝试安装任何使用 pip 的包。

例如,要使用 pip 安装 requests 包,请从 cmd 运行以下命令:

pip install requests

Whola! requests 将成功安装,您将收到一条成功消息。

Working as of Feb 04 2014 :):

If you have tried installing pip through the Windows installer file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip as suggested by @Colonel Panic, you might have installed the pip package manager successfully, but you might be unable to install any packages with pip. You might also have got the same SSL error as I got when I tried to install Beautiful Soup 4 if you look in the pip.log file:

Downloading/unpacking beautifulsoup4
  Getting page https://pypi.python.org/simple/beautifulsoup4/
  Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: **connection error: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed**
  Will skip URL https://pypi.python.org/simple/beautifulsoup4/ when looking for download links for beautifulsoup4

The problem is an issue with an old version of OpenSSL being incompatible with pip 1.3.1 and above versions. The easy workaround for now, is to install pip 1.2.1, which does not require SSL:

Installing Pip on Windows:

  1. Download pip 1.2.1 from https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz
  2. Extract the pip-1.2.1.tar.gz file
  3. Change directory to the extracted folder: cd <path to extracted folder>/pip-1.2.1
  4. Run python setup.py install
  5. Now make sure C:\Python27\Scripts is in PATH because pip is installed in the C:\Python27\Scripts directory unlike C:\Python27\Lib\site-packages where Python packages are normally installed

Now try to install any package using pip.

For example, to install the requests package using pip, run this from cmd:

pip install requests

Whola! requests will be successfully installed and you will get a success message.

百变从容 2024-10-20 05:22:15

简单CMD方式

使用CURL下载get-pip.py

curl --http1.1 https://bootstrap.pypa.io/get-pip.py --output get-pip.py

执行下载的Python文件

python get-pip.py

然后将 C:\Python37\Scripts 路径添加到环境变量中。 假设您的 C 盘中有一个 Python37 文件夹。该文件夹名称可能会根据安装的 Python 版本而有所不同

现在您可以通过运行来安装 Python 包

pip install awesome_package_name

Simple CMD way

Use CURL to download get-pip.py:

curl --http1.1 https://bootstrap.pypa.io/get-pip.py --output get-pip.py

Execute the downloaded Python file

python get-pip.py

Then add C:\Python37\Scripts path to your environment variable. It assumes that there is a Python37 folder in your C drive. That folder name may vary according to the installed Python version

Now you can install Python packages by running

pip install awesome_package_name
一束光,穿透我孤独的魂 2024-10-20 05:22:15

如果您使用的是从 python.org,但您需要升级 pip。

在 Windows 上,升级可以轻松完成:

转到 Python 命令行并运行以下 Python 命令

python -m pip install -U pip

使用 get-pip.py 安装

下载 get-pip.py 位于同一文件夹或您选择的任何其他文件夹中。我假设您将其下载到包含 python.exe 文件的同一文件夹中并运行此命令:

python get-pip.py

Pip 的 安装指南非常干净简单。

使用它,您应该能够在两分钟内开始使用 Pip。

pip is already installed if you're using Python 2 >= 2.7.9 or Python 3 >= 3.4 binaries downloaded from python.org, but you'll need to upgrade pip.

On Windows, the upgrade can be done easily:

Go to a Python command line and run the below Python command

python -m pip install -U pip

Installing with get-pip.py

Download get-pip.py in the same folder or any other folder of your choice. I am assuming you will download it in the same folder from where you have the python.exe file and run this command:

python get-pip.py

Pip's installation guide is pretty clean and simple.

Using this, you should be able to get started with Pip in under two minutes.

薄荷梦 2024-10-20 05:22:15

安装适用于 Python 2 和 Python 3 的 Pip

  1. get-pip.py 下载到计算机上的文件夹。
  2. 打开命令提示符并导航到包含 get-pip.py 的文件夹。
  3. 运行以下命令:python get-pip.pypython3 get-pip.pypython3.6 get-pip.py,具体取决于您想要在哪个版本的 Python 上安装 pip
  4. Pip 现在应该已经安装了!

旧答案(仍然有效)

尝试:

python -m ensurepip

这可能是在任何系统上安装 pip 的最简单方法。

Installing Pip for Python 2 and Python 3

  1. Download get-pip.py to a folder on your computer.
  2. Open a command prompt and navigate to the folder containing get-pip.py.
  3. Run the following command:python get-pip.py, python3 get-pip.py or python3.6 get-pip.py, depending on which version of Python you want to install pip
  4. Pip should be now installed!

Old answer (still valid)

Try:

python -m ensurepip

It's probably the easiest way to install pip on any system.

苏璃陌 2024-10-20 05:22:15

如果您的 pip 版本还有其他问题,您可以尝试以下操作:

pip install --trusted-host pypi.python.org --upgrade pip

If you even have other problems with the pip version, you can try this:

pip install --trusted-host pypi.python.org --upgrade pip
又爬满兰若 2024-10-20 05:22:15

现在,它与 Python 捆绑在一起。您不需要安装它。

pip -V

这是检查 pip 是否安装的方法。

在极少数情况下,如果未安装,请下载 get-pip.py 文件并使用 Python 运行它

python get-pip.py

Now, it is bundled with Python. You don't need to install it.

pip -V

This is how you can check whether pip is installed or not.

In rare cases, if it is not installed, download the get-pip.py file and run it with Python as

python get-pip.py
凉风有信 2024-10-20 05:22:15

我认为这个问题让答案看起来比实际情况更简单。

运行 pip 有时需要对模块进行本机编译(64 位 NumPy 是一个常见的示例)。为了使 pip 编译成功,您需要使用与 pip 所使用的 Microsoft Visual C++ 版本相同的 Python 进行编译。

标准 Python 发行版使用 Microsoft Visual C++ 2008 进行编译。您可以安装 Microsoft Visual C++ 2008 的 Express 版本,但不对其进行维护。最好的选择是获取更高版本的 Microsoft Visual C++ 的 Express 版本并编译 Python。然后 PIP 和 Python 将使用相同的 Microsoft Visual C++ 版本。

I think the question makes it seem like the answer is simpler than it really is.

Running of pip will sometimes require native compilation of a module (64-bit NumPy is a common example of that). In order for pip's compilation to succeed, you need Python which was compiled with the same version of Microsoft Visual C++ as the one pip is using.

Standard Python distributions are compiled with Microsoft Visual C++ 2008. You can install an Express version of Microsoft Visual C++ 2008, but it is not maintained. Your best bet is to get an express version of a later Microsoft Visual C++ and compile Python. Then PIP and Python will be using the same Microsoft Visual C++ version.

豆芽 2024-10-20 05:22:15

Windows 10 更新 - 仅 GUI

从现在起您只需访问 Microsoft Store,然后查找 Python:

在此处输入图像描述

哪个功能:

在此处输入图像描述

这是在 Windows 上安装 python 和 pip 最简单、最安全的方法。

Windows 10 Update - GUI only

From now on you can just access Microsoft Store, and look for Python:

enter image description here

Which feature:

enter image description here

That's the easiest and safest way to install python and pip on windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文