pythonnumpypython-3.7

Installing numpy with pip on windows 10 for python 3.7


I installed python 3.7 on my Windows 10 laptop since it has been officially released as of today (06/28/2018). Then i tried to install numpy package using pip

pip install numpy

The install proceeds but finally fails with the below error :

        source = func(extension, build_dir)
      File "numpy\core\setup.py", line 675, in get_mathlib_info
        raise RuntimeError("Broken toolchain: cannot link a simple C program")
    RuntimeError: Broken toolchain: cannot link a simple C program

    ----------------------------------------
Command ""c:\program files\python37\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\pcheg\\AppData\\Local\\Temp\\pip-install-7wjkw5wn\\numpy\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\pcheg\AppData\Local\Temp\pip-record-uhj8233f\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\pcheg\AppData\Local\Temp\pip-install-7wjkw5wn\numpy\

Any ideas as to how to overcome this install Error? Thanks.


Solution

  • Installing NumPy on Windows is a common problem if you don't have the right build setup. Instead, I always go to Christoph Gohlke's website to download the wheels you can install for your computer. Christoph generously builds the libraries himself with the right build environment, and he posts them on his website. These are specifically pre-compiled wheels made for Windows. I've found that Christoph Gohlke's website of pre-compiled wheels is the best way to install the NumPy and SciPy packages on Windows.

    Currently, Christoph Gohlke hosts those wheels on his Github page found here: https://github.com/cgohlke/numpy-mkl-wheels/

    Visit the Releases page. In the section that is the most up-to-date, make sure you click on the "Show all assets" link to uncover all of the wheels he has built, including NumPy and SciPy.

    Right-click on the one that is specifically for your computer and download it. For example, numpy-1.26.3-cp311-cp311-win_amd64.whl indicates that this is NumPy 1.26.3, Python 3.11, Windows 64-bit.

    Once downloaded, use pip to install the wheel:

    pip install numpy-1.26.3-cp311-cp311-win_amd64.whl
    

    This assumes you run the command in the same directory where you saved the wheel file. On the Releases page, search for the filename that is specifically for your machine according to the suitable Python, NumPy, and bit versions suitable for your environment and download the file, then run pip install as above.


    These instructions are now out of date - keeping these for prosperity

    First, install pipwin from PyPI which will install a utility that acts like pip but it will download the actual package you're interested in from his website, then use pipwin install to install the package you want.

    First do:

    pip install pipwin

    When that's installed, you can then do:

    pipwin install numpy

    This will install the latest version of NumPy on your system. This way you don't have to specifically search for the version of NumPy that is for your specific version of Python.