Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GMPY2 Not installing, mpir.h not found

I am trying to install gmpy2 on my Anaconda Python 3.5 distribution using pip. I was able to install other modules such as primefac perfectly. When I try to install gmpy2 this is what I get:

(C:\Program Files\Anaconda3) C:\WINDOWS\system32>pip install gmpy2
Collecting gmpy2
  Using cached gmpy2-2.0.8.zip
Building wheels for collected packages: gmpy2
  Running setup.py bdist_wheel for gmpy2 ... error
  Complete output from command "C:\Program Files\Anaconda3\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\HADIKH~1\\AppData\\Local\\Temp\\pip-build-hd7b270n\\gmpy2\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d C:\Users\HADIKH~1\AppData\Local\Temp\tmplefsjn80pip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_ext
  building 'gmpy2' extension
  creating build
  creating build\temp.win-amd64-3.5
  creating build\temp.win-amd64-3.5\Release
  creating build\temp.win-amd64-3.5\Release\src
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMPIR -DWITHMPFR -DWITHMPC "-IC:\Program Files\Anaconda3\include" "-IC:\Program Files\Anaconda3\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\\winrt" /Tcsrc\gmpy2.c /Fobuild\temp.win-amd64-3.5\Release\src\gmpy2.obj
  gmpy2.c
  c:\users\hadi khan\appdata\local\temp\pip-build-hd7b270n\gmpy2\src\gmpy.h(104): fatal error C1083: Cannot open include file: 'mpir.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

  ----------------------------------------
  Failed building wheel for gmpy2

I have noticed that whenever I try installing gmpy2 on a computer I always get some sort of error and it is a different one every time. Can someone please tell me how to fix this.

Thanks.

like image 953
Hadi Khan Avatar asked Oct 16 '16 20:10

Hadi Khan


3 Answers

The reason is some required packages (especially below packages) aren't installed.

  • GMP: GNU Multiple Precision Arithmetic Library
  • MPFR: GNU Multiple-precision floating-point rounding library
  • MPC: GNU Multiple-precision C library

you could install those packages by below commands:

apt-get install libgmp-dev
apt-get install libmpfr-dev
apt-get install libmpc-dev

I could install gmpy2 by installing those libraries.

the key point is remembering below hint when you got an error like above.

# include "***.h": ==> No such file or directory

apt-get install lib"***"-dev

like image 154
Lord ST Avatar answered Sep 29 '22 03:09

Lord ST


I maintain gmpy2 and unfortunately I have not been able to build Windows binaries for Python 3.5 and later. gmpy2 relies on either the MPIR or GMP libraries, and the MPFR and MPC libraries. There are detailed instructions included in the source distribution but they are not trivial to build on Windows. It is probably impossible(*) to build MPIR, MPFR, and MPC via pip. I would use the pre-compiled binaries available from http://www.lfd.uci.edu/~gohlke/pythonlibs/

(*) I'm sure it is possible with enough effort but I haven't done it.

like image 44
casevh Avatar answered Sep 29 '22 04:09

casevh


The answer above works as noted, but i had to also find out how to install a wheel, which is answered here How do I install a Python package with a .whl file? specifically, by copying the wheel file and executing (in my case), using pip 9

pip install C:\Python35\gmpy2-2.0.8-cp35-cp35m-win32.whl

like image 24
ocopa Avatar answered Sep 29 '22 04:09

ocopa