pythonwindowsnumpyscipyimporterror

Import error installing SciPy


I've facing serious troubles in trying to install the SciPy package on Windows...

I keep getting this error:

ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

Original error was: DLL load failed: The specified procedure could not be found.

followed by this:

Command "C:\Users\...\AppData\Local\Programs\Python\Python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\...\\AppData\\Local\\Temp\\pip-build-xm76_hu7\\scipy\\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\...\AppData\Local\Temp\pip-epfoebfp-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\...\AppData\Local\Temp\pip-build-xm76_hu7\scipy\

Really don't know how to solve this, I tried:


Solution

  • Usually installing SciPy on Windows through pip has a lot of troubles as there are dependencies that are required for you to compile which are known to be trouble on this operating system.

    The best way that I've found to get them to work is to install pre-compiled wheels made specifically for Windows. I've found that Christoph Gohlke's website of pre-compiled wheels is the best way to install 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, then for 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, which include NumPy and SciPy.

    Right-click on the one that is specifically for your computer and download it, so 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
    

    Change the filename and download the right file according to the right Python version, NumPy version and bit version that is specific for your machine.


    Note - this information is currently out of date - leaving for prosperity

    http://www.lfd.uci.edu/~gohlke/pythonlibs/

    The SciPy wheel requires NumPy compiled under MKL through his website, but that's also available through him as well.

    First install the NumPy + MKL wheel: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

    You need to make sure you choose the correct Python version and bit version for your Python. You can see that in the file name of each wheel. For example, numpy‑1.13.1+mkl‑cp34‑cp34m‑win_amd64.whl is for Python 3.4, 64 bit.

    Download it, save it to your computer then use pip to install the wheel:

    pip install numpy‑1.13.1+mkl‑cp34‑cp34m‑win_amd64.whl
    

    This is assuming you are running pip in the same directory where you downloaded the wheel. Change the filename to whatever version you downloaded in the above command.

    Once you install that, then go ahead and install SciPy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy. Make sure you choose the correct Python version and bit version as well.

    After this, it'll hopefully resolve any SciPy errors you have as it'll be based off of a working distribution of it.