如何在Windows上安装pip?

问题:如何在Windows上安装pip?

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

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


回答 0

Python 2.7.9+和3.4+

好消息!Pip随附了Python 3.4(2014年3月发布)和Python 2.7.9(2014年12月发布)。这是所有Python版本中的最佳功能。它使每个人都可以访问社区丰富的图书馆。新手不再因设置的困难而无法使用社区库。在与软件包管理器一起交付时,Python加入了RubyNode.jsHaskellPerlGo以及几乎所有其他具有主流开源社区的当代语言。谢谢,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/zh-CN/stable/installing/#do-i-need-to-install-pip

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

python get-pip.py

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

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

替代说明

官方文档告诉用户从源代码安装Pip及其每个依赖项。对于新手来说,这是乏味的,对新手来说却是困难重重。

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

  1. 安装setuptools
  2. 安装点子

对我来说,此安装点位于C:\Python27\Scripts\pip.exepip.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的工具。或尝试使用Microsoft Visual C ++编译器Python 2.7

尽管通常更容易检查Christoph网站上的包裹。

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 …\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.


回答 1

过时的 -使用分发,而不是此处所述的setuptools。-
过时的#2 -使用作为setuptools的分配已经过时了。

如前所述,pip不包含独立的安装程序,但是您可以使用其前身easy_install进行安装。

所以:

  1. 从此处下载最新的pip版本:http : //pypi.python.org/pypi/pip#downloads
  2. 解压缩
  3. 下载适用于Windows的最后一个简易安装程序:(http://pypi.python.org/pypi/setuptools底部下载.exe)。安装它。
  4. 将未压缩的pip文件夹内容复制到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 :)


回答 2

2014年更新:

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

2)如果您运行的版本低于Python 3.4,或者由于某些原因未在Python 3.4中安装pip,则您可能会使用pip的官方安装脚本get-pip.py。pip安装程序现在可以为您获取setuptools,并且可以在不考虑体系结构(32位或64位)的情况下运行。

这里详细说明了安装说明,其中包括:

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

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

python get-pip.py

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

为了后代,我将在下面保留两组旧说明。

旧答案:

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

使用分配的OLD方法2

  1. 下载分发 -我投入了我的想法C:\Python27\ScriptsScripts如果目录不存在,请随意创建。
  2. 打开命令提示符(在Windows上,如果不使用PowerShell,则应检出connemu2),然后将()更改为下载到的目录。cddistribute_setup.py
  3. 运行distribute_setup :(python distribute_setup.py如果您的python安装目录未添加到路径中,则此方法将不起作用- 请在此处获得帮助
  4. 将当前目录更改Scripts为Python安装目录(C:\Python27\Scripts),或者将该目录以及Python基本安装目录添加至您的%PATH%环境变量。
  5. 使用新安装的setuptools安装pip: easy_install pip

除非您easy_install.exe位于目录中(C:\ Python27 \ Scripts将是Python 2.7的默认设置),或者您将该目录添加到路径中,否则最后一步将不起作用。

使用ez_setup的OLD方法1

从setuptools页面

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

之后,您可以继续:

  1. 添加c:\Python2x\Scripts到Windows路径(用已安装的实际版本号替换xin Python2x
  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

回答 3

2016年更新:

这些答案已经过时,或者罗word且困难。

如果您拥有Python 3.4+或2.7.9+,它将默认安装在Windows上。否则,简而言之:

  1. 下载pip安装程序:https : //bootstrap.pypa.io/get-pip.py
  2. 如果偏执,请检查文件以确认它不是恶意的(必须b64解码)。
  3. 以Admin身份在下载文件夹中打开一个控制台,然后运行 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.


回答 4

2014年3月 发布的Python 3.4 pip附带了以下内容:
http : //docs.python.org/3.4/whatsnew/3.4.html
因此,自Python 3.4发布以来,最新的安装pip方法在Windows上只是安装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


回答 5

当我必须使用Windows时,我使用ActivePython,它将自动将所有内容添加到您的PATH中,并包括一个名为PyPM的软件包管理器,该软件包管理器提供了二进制软件包管理,从而使安装软件包变得更快,更简单。

pipeasy_install不是完全一样的东西,所以有一些事情可以打通pip,但不是easy_install ,反之亦然

我的建议是您获得ActivePython社区版,不要担心在Windows上为Python设置所有东西的麻烦。然后,您可以使用pypm

如果要使用pip,则必须检查PyPMActiveState安装程序中的选项。安装后,您只需要注销并再次登录,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.


回答 6

最新的方法是使用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.


回答 7

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也将为您安装它。

如评论中所述,以上命令将从GitHub上的Pip源代码存储库下载代码,并在您的环境中动态运行它。因此请注意,这是下载,检查和运行步骤的快捷方式,所有这些操作都使用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).


回答 8

安装人员

我内置的Windows安装两种分发PIP这里(其目标是使用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

回答 9

以下内容适用于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

如果您使用的是Windows 7的64位版本,则可能会在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).


回答 10

对于最新的Python下载-我在Windows上安装了python 3.6。您不必怀疑所需的一切都在那里,请屏息,我将向您展示如何做到这一点。

  1. 确保为我安装python的位置在以下目录中

现在,如果您在Windows上,让我们将python和pip添加到环境变量路径设置中,以便在任何地方键入pip或python都可以从安装它们的地方调用python aor pip。

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

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

pip install google

再见!

For latest Python Download – I have python 3.6 on windows. You don’t have to wonder everything you need is there , take a breath i will show you how to do it.

  1. make sure where you install python for me its was in the following directory

Now , lets add python and pip into environment variable path settings if you are on windows, so that typing pip or python anywhere call python aor pip from where they are installed.

So, PIP is found under the folder in above screen “SCRIPTS” Lets add Python and PIP in environment variable path.

Almost Done , Let test with CMD to install goole package using pip.

pip install google

BYE BYE!


回答 11

要在Python 2.x上全局安装pip ,如Adrián所述,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

回答 12

要使用pip,并不一定需要直接在系统中安装pip。您可以通过使用它virtualenv。您可以按照以下步骤操作:

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

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

现在创建一个虚拟环境,在myproject文件夹中,如下所示说myvirtualenv

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,但是请确保已激活虚拟环境,方法是查看提示左侧的内容。

这是在虚拟环境中安装pip的最简单方法之一,但是您需要随身携带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.


回答 13

我只是想为那些无法从Windows 64位安装setuptools的用户添加一个解决方案。在python.org上的此错误中讨论了该问题,截至本评论发布之日仍未解决。提到了一个简单的解决方法,它可以完美地工作。一次注册表更改对我来说很成功。

链接: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\\"

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

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.


回答 14

更新于2016年: Pip应该已经包含在中Python 2.7.9+ or 3.4+,但是如果由于某种原因它不存在,则可以使用以下一种格式。

PS:

  1. 在大多数情况下,这已经可以满足要求,但是,如果有必要,请确保环境变量PATH包含Python的文件夹(例如,Python 2.7.x在Windows默认安装:C:\Python27 and C:\Python27\Scripts,for Python 3.3xC:\Python33 and C:\Python33\Scripts等)

  2. 我遇到同样的问题,然后在这里的官方网站上找到了这种最简单的方法(一行代码!): http //www.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!


回答 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.


回答 16

在这里,如何通过简单的方法安装pip。

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

Here how to install pip with easy way.

  1. copy and paste these content in a file as get-pip.py
  2. copy and paste get-pip.py into python folder.C:\Python27
  3. Double click to get-pip.py file.it will install pip to your computer.
  4. Now you have to add C:\Python27\Scripts path to your enviroment variable.Because it includes pip.exe file.
  5. Now you are ready to use pip. Open cmd and type as
    pip install package_name

回答 17

PythonXY带有pip包括,除其他

PythonXY comes with pip included, among others.


回答 18

我在Windows上使用来自continuum.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.


回答 19

按照此处的说明进行安装时,我遇到了一些问题。我认为以相同的方式在每个Windows环境中安装非常棘手。就我而言,出于同一目的,我需要在同一台计算机上使用Python 2.6、2.7和3.3,这就是为什么我认为还有更多问题的原因。但是以下说明对我来说非常有效,因此可能要根据您的环境尝试使用此说明:

http://docs.python-guide.org/zh-CN/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.


回答 20

  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.


回答 21

很简单:

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.)


回答 22

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

如果您按照@Colonel Panic的建议尝试通过Windows安装程序文件从http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip安装pip ,则可能已成功安装了pip软件包管理器,但是您可能无法使用pip安装任何软件包。如果您查看pip.log文件,您可能还会遇到与尝试安装Beautiful Soup 4时遇到的SSL错误相同的错误:

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及更高版本不兼容。目前,最简单的解决方法是安装不需要SSL的 pip 1.2.1

在Windows上安装Pip:

  1. https://pypi.python.org/packages/source/p/pip/pip-1.2.1.tar.gz下载pip 1.2.1
  2. 提取pip-1.2.1.tar.gz文件
  3. 将目录更改为提取的文件夹: cd <path to extracted folder>/pip-1.2.1
  4. python setup.py install
  5. 现在确保C:\Python27\Scripts位于PATH中,因为pip安装在C:\Python27\Scripts目录中,这与C:\Python27\Lib\site-packages通常安装Python软件包的位置不同

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

例如,要requests使用pip 安装软件包,请从cmd运行此命令:

pip install requests

哇!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.


回答 23

如果您使用的是从python.org下载的Python 2> = 2.7.9或Python 3> = 3.4二进制文件,则已经安装了pip,但是您需要升级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 upgrade can be done easily

Go to Python command line and run 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 you have 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.


回答 24

如果您甚至对pip版本有其他问题,可以尝试一下

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

if you even have other problems with pip version you can try this

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

回答 25

简单的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路径添加到您的环境变量。假设Python37您的C盘中有一个文件夹,该文件夹的名称可能会因安装的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 downloaded python file

python get-pip.py

Then add C:\Python37\Scripts path to your environment variable. Assumes that there is a Python37 folder in your C drive, that folder name may varied according to the installed python version

Now you can install python packages by running

pip install awesome_package_name

回答 26

Python2和安装PipPython3

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

旧答案(仍然有效)

你有没有尝试过 ?

python -m ensurepip

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

Installing Pip for Python2 and Python3

  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)

Have you tried ?

python -m ensurepip

it’s probably the easiest to install pip on any system.


回答 27

只需从此处https://pypi.python.org/pypi/setuptools#windows-simplified下载setuptools-15.2.zip(md5),然后运行ez_setup.py。

Just download setuptools-15.2.zip (md5), from here https://pypi.python.org/pypi/setuptools#windows-simplified , and run ez_setup.py.


回答 28

或者,您可以获得pip-Win,它是pip的多合一安装程序,并且virtualenv在Windows及其GUI上。

  • 从一个Python解释器(即版本)切换到另一个(包括py和pypy)
  • 查看所有已安装的软件包,以及它们是否为最新
  • 安装或升级软件包,或升级pip本身
  • 创建和删除虚拟环境,并在它们之间切换
  • 使用选定的解释器运行IDLE或其他Python脚本

Alternatively, you can get pip-Win which is an all-in-one installer for pip and virtualenv on Windows and its GUI.

  • Switch from one Python interpreter (i.e. version) to another (including py and pypy)
  • See all installed packages, and whether they are up-to-date
  • Install or upgrade a package, or upgrade pip itself
  • Create and delete virtual environments, and switch between them
  • Run the IDLE or another Python script, with the selected interpreter

回答 29

现在,它与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 case, if it is not installed, download get-pip.py file and run it with python as

python get-pip.py