12

I have brew installed mpcand gmp , but when I try to pip install gmpy2 I get a compile error on the line

#include "mpc.h"

so for some reason clang is having trouble finding the mpc library. I'm not sure what I should do at this point.

Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65

5 Answers5

50

For OSX with homebrew users - I tried to do the usual dance with

brew install mpc
brew install mpfr

and then

python setup.py --prefix=/usr/local/Cellar

but got the error, that 'mpc.h' could not be found. True enough, there is no mpc.h file to be found. The solution is, to use

brew install libmpc
brew install mpfr

instead. After that gmpy2 was compiling and installing with no further problems.

Marc Glisse
  • 7,550
  • 2
  • 30
  • 53
Werner Thie
  • 501
  • 4
  • 3
  • 3
    I would like to point out one subtle misunderstanding mpc is "Command-line music player client for mpd" while **libmpc** is "C library for the arithmetic of high precision complex numbers". The second is what we want to install. call _brew info_ in case of hesitation. – MichK Oct 11 '17 at 09:44
  • 2
    This answer should be updated to just `brew install libmpc` because `mpfr` is a dependency of `libmpc` and `mpc` is not the library you are looking for. – Keith Shaw May 01 '18 at 00:33
17

The short and sweet 2015 answer:

brew install mpfr
brew install libmpc
pip install gmpy2
wim
  • 338,267
  • 99
  • 616
  • 750
  • Just tried this and it works on a clean OS X Mojave install. 10.14.5. Installed with pip3 install --user gmpy2 after the brew installation of mpfr and libmpc. – Albert Veli May 25 '19 at 09:19
7

I'm the maintainer for gmpy2. I don't have access to a Mac so I can't test OSX builds.

I assume you've also installed mpfr since it is a prerequisite of mpc. Where are the development files (i.e. gmp.h, mpfr.h, and mpc.h) located?

Instead of installing via pip, can you try installing from the command line? I use a command similar to:

python setup.py install --prefix=/opt/local --force

This command assumes that the .h files are located in /opt/local/include. You will need to adjust the prefix to suit your system.

casevh
  • 11,093
  • 1
  • 24
  • 35
  • Apparently the .h files don't exist anywhere on my system, so I'm installing from the command line through the tutorial on Google Code. Thanks! – Jakob Weisblat Apr 20 '14 at 23:20
  • @JakobWeisblat Please let me know if the installation instructions need clarification or can be improved. – casevh Apr 21 '14 at 02:15
2

As of the 06 March 2018, the only thing that worked for me was the following. (Install on Mac OS High Sierra 10.13.3, for python 3.5.4)

sudo port install libmpc
sudo port install gmp
sudo pip3 install --global-option=build_ext --global-option="-I/opt/local/include/" --global-option="-L/opt/local/lib/" gmpy2

Note that sudo port install libmpc automatically installs mpfr as a dependency. --global-option="-I/opt/local/include/" basically tells the system that the header files for gmp, mpc and mpfr are in /opt/local/include/ and --global-option="-L/opt/local/lib/" tells that the libraries to use are located in /opt/local/lib/.

0

If you are using anaconda or miniconda, install mpc and mpfr from conda-forge and then install gmpy

conda install -c conda-forge mpc mpfr
pip install gmpy2
mrdependable
  • 1
  • 1
  • 1