87

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?

David Y. Stephenson
  • 872
  • 4
  • 22
  • 44
  • 1
    why not? have you installed pip for this python installation? what error do you get? – mata Sep 05 '13 at 16:37
  • Pip is installed, but it installs the python 2 version of the package. For example, my script that requires pyyaml returns `ImportError: No module named yaml`, even after successfully running `pip install pyyaml`. – David Y. Stephenson Sep 05 '13 at 16:42
  • 1
    Then the `pip` script doesn't run with the correct python version. Try `/path/to/python3 -m pip install ...` instead. Also, check the shebang of the pip script. – mata Sep 05 '13 at 16:58
  • @mata FYI, Python 2 is also installed. `usr/bin/python3 -m pip install pyyaml` returns `/usr/bin/python3: No module named pip`. Thus my original question; how does one install pip-3 on cygwin? – David Y. Stephenson Sep 05 '13 at 17:55
  • 1
    `python3 -m ensurepip` and `python2 -m ensurepip`. Look to https://www.python.org/dev/peps/pep-0453/ – gavenkoa Sep 11 '17 at 16:40

6 Answers6

130

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

2) Type the following command:

easy_install-a.b pip   

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

DomainsFeatured
  • 1,426
  • 1
  • 21
  • 39
moovon
  • 2,219
  • 1
  • 17
  • 15
  • 4
    This answer worked great for me. I had to take a couple extra steps because I work at a university: First, I navigated to my install path (c:/cygwin64/bin/). Then had auto complete help me find the easy install file named slightly differnt: easy_install 2.7.9 – Protomancer Oct 30 '15 at 18:26
  • 6
    I did this to end up in a state without eggs: `easy_install-2.7 pip && pip install 'pip<8' && pip install pip --upgrade` – anthony sottile Mar 20 '16 at 04:52
  • 6
    for python3, use python3 & **python3-setuptools** packages. It's obvious, but one can forget about python**3**-setuptools – simon Jun 11 '16 at 17:54
  • 2
    And don't forget the version (ie -2.7). I had another python distribution on my computer, and 'easy_install' invoked that one rather than cygwin's. – jtbr Jan 28 '17 at 21:28
45

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.py and run it with python3:

/usr/bin/python3 ez_setup.py

That should install setuptools, and also create an easy_install script for your python version, e.g. /usr/bin/easy_install-3.2, which you can use to install 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.

Alternatively you can follow the install instructions from here and here.

mata
  • 67,110
  • 10
  • 163
  • 162
29

I think the alternative install instructions linked by mata are simplest:

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

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

python get-pip.py
Community
  • 1
  • 1
svick
  • 236,525
  • 50
  • 385
  • 514
15

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.

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


EDIT: 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.

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

  • 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 pip has replaced/updated the files in that package. Check with: cygcheck.exe -c |grep Incomplete.
    Do not re-install those packages with Cygwin.

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

So what I did, was clear out all python3 related Cygwin packages, except the Python3 itself. Then I re-installed the only one needed: 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 setuptools dependencies with the latest updates.

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

not2qubit
  • 14,531
  • 8
  • 95
  • 135
  • is `ensurepip` necessary because of cygwin? Usually, `pip` is on board, see [here](https://docs.python.org/3/library/ensurepip.html) – Timo Jul 10 '18 at 21:09
  • @Timo, for me it was, for whatever reason I was missing pip3 for python3 – Lepidopteron Jul 15 '18 at 14:17
  • As long as you have `pip` installed, you can always symlink in `/usr/bin/`, but perhaps its more elegant to use the native *ensurepip* fix. IDK if I already had an old version or if it was installed along with `setuptools`, but I don't have the `ensurepip` package installed. – not2qubit Nov 15 '18 at 15:54
  • 2
    +1 for recommending kou1okada's fork of apt-cyg, it's the most fully-featured and best-maintained by far, been using it for years. – Hashim Aziz Mar 17 '20 at 16:05
2

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

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

Python 3

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

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

/usr/bin/python2.7 -m ensurepip 

or

/usr/bin/python3.6 -m ensurepip
Nitin_k29
  • 341
  • 1
  • 3
  • 7
0

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