6

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.

Donkey
  • 3
  • 2
Hadi Khan
  • 577
  • 2
  • 8
  • 30

4 Answers4

17

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

Lord ST
  • 513
  • 7
  • 15
  • 1
    in windows you can install pip with cygwin and when installing cygwin's packages remember to install above packages and python/python-setuptools. – Lord ST Dec 28 '16 at 11:47
  • 1
    On a Mac: `brew install gmp` `brew install mpfr` `brew install mpc` – Joao Coelho Jun 20 '18 at 17:54
  • solved my problem installing gmpy2 include "mpfr.h" | ^~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 – florian.isopp Nov 29 '20 at 21:27
16

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.

casevh
  • 11,093
  • 1
  • 24
  • 35
  • I'm trying to use gmpy2 as well, are you telling me that it would work if I downgrade to python 3.4.10 or something? – Hades Jul 27 '20 at 10:08
3

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

Community
  • 1
  • 1
ocopa
  • 75
  • 8
1

enter image description hereUse conda to install instead of pip. conda will take care of installing the necessary dependencies. The command is: conda install gmpy2