Installing SciPy, NumPy and matplotlib Under Cygwin

Today I tried installing these modules under Cygwin with pip. The whole thing took a few hours to figure out thanks to crappy bundled packages that pip fetches and lack of consistency between helps available online.

To install pip, you need to have python3-setuptoolsinstalled. Then using the easy_install3 pip command you can install pip.

After that, you need to have liblapack-devel and libopenblas installed via Cygwin’s package manager (SciPy depends on them). You also need to have gcc-fortran, python-gtk2, tcl-tk, libpng, pkg-config and a bunch of other stuff (that pip installer complains about) installed. The dependencies that pip complains about are straightforward (just mark them for installation in Cygwin’s installer).

Running pip -v install numpy and pip -v install matplotlib should get you those packages without much headache. The most important thing is that as of SciPy v 0.16.1, there seems to be some error in SciPy’s C files that prevents compilation and installation. I was able to get it to install using pip -v install scipy==0.15.1.

After installation, you may notice that you can’t plot stuff using mathplotlib’s pyplot module. To fix that, you need to have XWinServer running and should configure matplotlib to use tkagg backend. To do this, locate the file matplotlibrc and change backend      : agg to backend      : tkagg. The plots should show now!

16 thoughts on “Installing SciPy, NumPy and matplotlib Under Cygwin”

  1. I’ve been banging my head against cygwin for the better part of the day today… I can’t seem to get matplotlib to install. This is what it’s saying:
    Removing source in /tmp/pip-build-ZCY_A8/matplotlib
    Command “/cygdrive/c/labs/virtualenvs/vistafy/bin/python2.7 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-ZCY_A8/matplotlib/’;exec(compile(getattr(tokenize, ‘open’, open)(__file__).read().replace(‘\r\n’, ‘\n’), __file__, ‘exec’))” install –record /tmp/pip-N21S7w-record/install-record.txt –single-version-externally-managed –compile –install-headers /cygdrive/c/labs/virtualenvs/vistafy/include/site/python2.7/matplotlib” failed with error code 1 in /tmp/pip-build-ZCY_A8/matplotlib/

    Any ideas?

      1. Ah man I wish it would’ve notified me that you replied. I gave up for a while and used my vagrant box. I’ve been trying again today though. It has something to do with my libfreetype I’ve noticed. the problem I had before was really just something that it was throwing later. This is the problem:

        gcc -fno-strict-aliasing -ggdb -O2 -pipe -Wimplicit-function-declaration -fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.i686/build=/usr/src/debug/python-2.7.8-1 -fdebug-prefix-map=/usr/src/ports/python/python-2.7.8-1.i686/src/Python-2.7.8=/usr/src/debug/python-2.7.8-1 -DNDEBUG -g -fwrapv -O3 -Wall -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -I/home/lucky_000/.virtualenvs/vistafy/lib/python2.7/site-packages/numpy/core/include -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include -I. -I/usr/include/python2.7 -c src/ft2font.cpp -o build/temp.cygwin-1.7.35-i686-2.7/src/ft2font.o
        gcc: error: spawn: No such file or directory

        I’m not sure what file it’s looking for that it can’t find. It’s very likely that cygwin just eff’ed up and put it in the wrong place or something and I could fix with a symbolic link, but the error isn’t exactly descriptive.

  2. I was happy to come across this but have not found it to be so easy. I’m attempting to set up python 2.7, however; perhaps that is a fool’s errand. Anyway, I’m bombing out trying to update numpy, I have no xlocale.h!

    Looking for this in the Cygwin distribution, I ended up installing many of the KDE packages, didn’t help.

    I’d say I’m going to keep trying but I don’t have the time. If you have any insight, I’d love to hear it.


  3. Hi Mehran

    I tried the command:
    pip -v install scipy==0.15.1

    and get this error:

    Command “/usr/bin/python2.7 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-BZbhrN/scipy/’;f=getattr(tokenize, ‘open’, open)(__f;‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-Ia80Ko-record/install-record.txt –sversion-externally-managed –compile” failed with error code 1 in /tmp/pip-build-BZbhrN/scipy/
    Exception information:
    Traceback (most recent call last):
    File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/”, line 215, in main
    status =, args)
    File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/”, line 342, in run
    File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/”, line 784, in install
    File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/”, line 878, in install
    File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/”, line 707, in call_subprocess
    % (command_desc, proc.returncode, cwd))
    InstallationError: Command “/usr/bin/python2.7 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-build-BZbhrN/scipy/’;f=getattr(tokenizen’, open)(__file__);‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-Ia80Ko-record/insecord.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-build-BZbhrN/scipy/

  4. I keep getting this:

    Traceback (most recent call last):
    File "", line 1, in
    File "/tmp/pip-build-AIAy3f/scipy/", line 249, in
    File "/tmp/pip-build-AIAy3f/scipy/", line 237, in setup_package
    from numpy.distutils.core import setup
    File "/usr/lib/python2.7/site-packages/numpy/", line 142, in
    from . import add_newdocs
    File "/usr/lib/python2.7/site-packages/numpy/", line 13, in
    from numpy.lib import add_newdoc
    File "/usr/lib/python2.7/site-packages/numpy/lib/", line 17, in
    from . import scimath as emath
    ImportError: cannot import name scimath

    It doesn’t make any sense, scimath does exist there! This happens regardless of python version or scipy version. All other things have been installed.

  5. Hi, thanks for the info, surely useful. However, what I was missing (and wasn’t clear from the pip log) was python3-devel module in Cygwin. If your installation is complaining about Python.h missing, that might be your issue too.
    Hope it might help others 😉

  6. Wow, did this posting save me a lot of time! Thank you, thank you, thank you. I’m forced to use a win7 host for something (I’ve been a desktop linux-only for about 15 years). I’m working with an analog discovery 2 kit and wanted to develop using vi on cygwin which mostly tolerable.

    Addition to your post, after you install numpy, pip exits without errors but continuing install results in a lapack error something like this

    from numpy.linalg import lapack_lite, _umath_linalg

    you need to add /usr/lib/lapack to your PATH.

    export PATH=$PATH:/usr/lib/lapack

    you have to get numpy running correctly for matplotlib install to happen, plus a bunch of other cygwin installs as mentioned here. Yes, you cygwin setup install a bunch of stuff, including g++, c compiler, fortran stuff, gtk stuff, etc etc etc. Here a cygcheck -c dump, sorry so long.

    After all this, I ran the AD2 script and a plot showed up in x, yay!!!

    Good luck fellow lazy Linux programmers like me!

  7. I think it’s easier to just install Anaconda and then put the path to the python binaries in your ~/.bash_profile. That’s what I’ve done for Java, R, and Go and it seems preferable to dealing with Cygwin’s crudginess.

    Nonetheless, thanks for publishing this.

Leave a Reply

Your email address will not be published. Required fields are marked *