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-setuptools`installed. 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!
27 comments
Skip to comment form
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/setup.py’;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?
Author
Hey Alex,
Can you tell me what steps you’ve taken so far?
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.
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.
Best,
KSH
You can try: ‘pip install xlocale’
didn’t work for me. this link suggested just linking locale.h to xlocale.h
https://forum.alpinelinux.org/forum/general-discussion/xlocaleh
some similar suggestions and details here http://serverfault.com/questions/771211/docker-alpine-and-matplotlib
I did get a successful numpy install afterwards
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/setup.py’;f=getattr(tokenize, ‘open’, open)(__f;code=f.read().replace(‘\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/basecommand.py”, line 215, in main
status = self.run(options, args)
File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py”, line 342, in run
prefix=options.prefix_path,
File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py”, line 784, in install
**kwargs
File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py”, line 878, in install
spinner=spinner,
File “/usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py”, 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/setup.py’;f=getattr(tokenizen’, open)(__file__);code=f.read().replace(‘\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/
Same here.
I keep getting this:
“`
Traceback (most recent call last):
File “”, line 1, in
File “/tmp/pip-build-AIAy3f/scipy/setup.py”, line 249, in
setup_package()
File “/tmp/pip-build-AIAy3f/scipy/setup.py”, line 237, in setup_package
from numpy.distutils.core import setup
File “/usr/lib/python2.7/site-packages/numpy/__init__.py”, line 142, in
from . import add_newdocs
File “/usr/lib/python2.7/site-packages/numpy/add_newdocs.py”, line 13, in
from numpy.lib import add_newdoc
File “/usr/lib/python2.7/site-packages/numpy/lib/__init__.py”, 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.
Thank you, this saved me a lot of time!
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 😉
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 AnalogIn_Acquisition.py script and a plot showed up in x, yay!!!
Good luck fellow lazy Linux programmers like me!
Craig
Author
Glad this helped you and thanks for sharing your experience with us!
I was waiting for this kind of matter. Thank you
very much for the place.
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.
Author
Glad you found the post useful.
This post is the answer to a prayer, thank yoouuuu!
cygwin, jupyter notebook, scipy …
Thank you! I have been combing the Internet for information on how to successfully install scipy on a Windows computer and cygwin. Your info about the Cygwin packages that were dependencies did the trick! After I installed, through the cygwin installer, liblapack-devel, libopenblas, gcc-fortran, python-gtk2, tcl-tk, libpng, and pkg-config (I already had this one), I was able to install scipy:
pip install scipy
with no problem. Thanks again!
Author
Happy to hear it helped you!
Hello. Thanks for the help. I could not install scipy and matplotlib. Python devel package solved my problem. I don’t know how to change matplotlibrc backend. What exactly is backend? I am new to this stuff so could you explain this to me? I don’t know how to do it. What do you mean by saying ‘you need to have xwin server running’ ? I installed xwin server packages with cygwin install.
Hi, I have been trying to install a more recent version of numpy (1.15) in my virtual environment, than the one currently available as a package from cygwin setup (1.11.2). However, I continue to encounter a raft of build errors. I have reviewed your cygcheck output above, ignoring versions as it is somewhat out of date. With the exception of a few “proto” packages, I seem to now have the same packages as you show above (plus a few unique to my Cygwin install). I attempt to do a “pip install numpy==1.15.0” in a python3 venv, and still encounter errors like the following (this is just a sample of several pages worth…)
…
blas_opt_info:
blas_mkl_info:
customize UnixCCompiler
libraries mkl_rt not found in [‘/home/gramer/sandbox3/lib’, ‘/usr/local/lib’, ‘/usr/lib’, ‘/usr/lib/’]
NOT AVAILABLE
…
gcc /tmp/tmpi7p40tvh/tmp/tmpi7p40tvh/source.o -L/usr/lib -lcblas -o /tmp/tmpi7p40tvh/a.out.exe
/bin/ld: cannot find -lcblas
collect2: error: ld returned 1 exit status
I have verified that there is *A* version of the blas library available, albeit I am not sure it is the right one:
# ls /usr/lib/lapack
cygblas-0.dll* cyglapack-0.dll*
The older version of numpy that comes as a package does not work with several newer packages that I need to use, so… Any help appreciated!
Lew Gramer
Mehran, thanks a million! As a newcomer to python I never would have been able to get my python2 scripts running without these simple instructions.
One thing I also had to do that wasn’t mentioned was to install the cygwin package python2-devel. Perhaps this package is obvious to regular python users?? Anyway, you’ll know you need to install it if you get gcc compilation errors such as ” fatal error: Python.h: No such file or directory”.
Author
Happy to help!
Thank you so much!
The bug in scipy is explained here:
https://github.com/scipy/scipy/pull/11320
Strangely, the fix (made Jan 5 2020) is still not merged into the master.
I used pip3-v install scipy==1.1 and version 1.1 compiled & installed fine in cygwin, though with about an hour of warnings. Maybe 1.3 would as well.
Thank you!
pip -v install scipy==0.15.1 reports errors, but
pip3 -v install scipy==1.1 worked for me, after I installed the cygwin packages you mentioned
Just wanted to say thanks
on cygwin was able to get
$ pip -v install scipy
Successfully installed scipy-1.6.2
I installed python38-numpy and python38-matplotlib ( and a few other packages from cygwin setup first )