Python 在 Cygwin 上安装 Pip-3.2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18641438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 11:17:52  来源:igfitidea点击:

Installing Pip-3.2 on Cygwin

pythonpython-3.xcygwinpip

提问by David Y. Stephenson

I have Python 3 installed on Cygwin. However, I am unable to install Python 3 packages via pip. Is there a way to do this?

我在 Cygwin 上安装了 Python 3。但是,我无法通过pip. 有没有办法做到这一点?

采纳答案by moovon

1)While installing cygwin, make sure you install the python/python-setuptools from the list. This will install "easy_install" package.

1) 在安装 cygwin 时,请确保从列表中安装了 python/python-setuptools。这将安装“easy_install”包。

2) Type the following command:

2) 输入以下命令:

easy_install-a.b pip   

You must replace a.bwith your python version which can be 2.7 or 3.4 or whatever else.

您必须替换a.b为 2.7 或 3.4 或其他任何版本的 python 版本。

回答by mata

If you have more than one python installation, then you need to install pip (and probably also setuptools) for each installation separately.
To do so, you can first download ez_setup.pyand run it with python3:

如果您有多个 python 安装,那么您需要为每个安装分别安装 pip(可能还有 setuptools)。
为此,您可以先下载ez_setup.py并使用 python3 运行它:

/usr/bin/python3 ez_setup.py

That should install setuptools, and also create an easy_installscript for your python version, e.g. /usr/bin/easy_install-3.2, which you can use to install pip:

这应该安装 setuptools,并easy_install为您的 python 版本创建一个脚本,例如/usr/bin/easy_install-3.2,您可以使用它来安装 pip:

/usr/bin/easy_install-3.2 pip

This will install pip into your python3 site packages directory, and again create a script /usr/bin/pip-3.2, which you can use to install packages for this python version.

这会将 pip 安装到您的 python3 站点包目录中,并再次创建一个脚本/usr/bin/pip-3.2,您可以使用它来安装此 python 版本的包。

Alternatively you can follow the install instructions from hereand here.

或者,您可以按照此处此处的安装说明进行操作。

回答by svick

I think the alternative install instructionslinked by mata are simplest:

我认为mata 链接的替代安装说明是最简单的:

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

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

python get-pip.py

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

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

python get-pip.py

回答by not2qubit

Since OP specifically talks about Python3, I think we need to specify that just in case the user already have Python2 installed, which is very likely.

由于OP专门谈到Python3,我认为我们需要指定以防万一用户已经安装了Python2,这很有可能。

# If you don't have Python3 already, use apt-cyg:
apt-cyg install python3

# First update pip, pip2 
pip2 install --upgrade pip 

# Install pip3:
python3 -m ensurepip

# Finally update pip3:
pip3 install --upgrade pip

$ pip3 -V
pip 9.0.1 from /usr/lib/python3.4/site-packages (python 3.4)

BTW. There are several forks of apt-cyg, but the best maintained is that of kou1okada, you'll love it.

顺便提一句。apt- cyg有几个分支,但维护得最好的是kou1okada 的分支,你会喜欢它的。



EDIT: 2018-11-15

编辑:2018-11-15

Because I started out not using virtualenv, I recently had to refresh my Cygwin Python3 installation, and realized a few things in the process that should have been obvious, but can easily be forgotten.

因为我一开始没有使用virtualenv,所以我最近不得不刷新我的 Cygwin Python3 安装,并且在这个过程中意识到了一些应该很明显但很容易被遗忘的事情。

  • When installing and using Python3 on Cygwin (and probably on most other *nix distros), onlyinstall the basic Python3 interpreter as a Cygwin package. From then on, only use the pipinstaller.

  • After you have installed or updated any python3 packages using pip, your Cygwin package manager will complain that your package is "Incomplete". That is because piphas replaced/updated the files in that package. Check with: cygcheck.exe -c |grep Incomplete.
    Do not re-install those packages with Cygwin.

  • 在 Cygwin(可能还有大多数其他 *nix 发行版)上安装和使用 Python3 时,将基本的 Python3 解释器安装为 Cygwin 包。从那时起,只使用pip安装程序。

  • 在您使用pip安装或更新任何 python3 软件包后,您的 Cygwin 软件包管理器会抱怨您的软件包是"Incomplete". 那是因为pip已经替换/更新了该包中的文件。检查:cygcheck.exe -c |grep Incomplete
    不要用 Cygwin 重新安装这些软件包。

# cygcheck.exe -c |grep Incomplete
python3-setuptools      34.3.2-1         Incomplete

So what I did, was clear out allpython3 related Cygwin packages, exceptthe Python3 itself. Then I re-installed the only one needed: python3-setuptools.

所以我所做的就是清除所有与 python3 相关的 Cygwin 包,除了Python3 本身。然后我重新安装了唯一需要的:python3-setuptools.

# apt-cyg remove python3-setuptools
apt-cyg install python3-setuptools

# Fix pip3 symlink (or just pip if you don't have python2)
ln -s /usr/bin/pip3.6 /usr/bin/pip3

# That also installs the Cygwin packages:  
# python3-appdirs, python3-packaging, python3-pyparsing, python3-six

# Now, update setuptools with pip:
pip3 install -U --force-reinstall --only-binary=:all: --no-clean --no-cache-dir setuptools

# pip list |grep setuptools
setuptools          40.5.0

That should have also have re-installed all the setuptoolsdependencies with the latest updates.

这还应该使用最新更新重新安装所有setuptools依赖项。

From now on, do yourself a favor and start using a virtual environment.

从现在开始,帮自己一个忙,开始使用虚拟环境。

回答by DanielW

I just learned, inspired from https://www.scivision.co/install-pip-in-cygwin/and the answer before, that instead of using pip, you just have to use pip2 for python2 or pip3 for python 3 in cygwin on windows. Wondered about this the whole day...

我刚刚从https://www.scivision.co/install-pip-in-cygwin/和之前的答案中学到了灵感,而不是使用 pip,你只需要在 cygwin 中使用 pip2 for python2 或 pip3 for python 3在窗户上。一整天都在想这个……

回答by Nitin_k29

On windows, you can use pip to install packages. If you have multiple python installations under cygwin, give the full python path e.g. Python 2

在 Windows 上,您可以使用 pip 来安装软件包。如果您在 cygwin 下有多个 python 安装,请提供完整的 python 路径,例如 Python 2

/usr/bin/python2.7 -m pip install pyyaml

Python 3

蟒蛇 3

/usr/bin/python3.6 -m pip install pyyaml

In case you dont have pip installed install it using below command

如果您没有安装 pip,请使用以下命令安装它

/usr/bin/python2.7 -m ensurepip 

or

或者

/usr/bin/python3.6 -m ensurepip