labs.beatcraft.com
OS X

Installing gmpy on Mac OS X

About gmpy

gmpy is a Python extension module, which enables Python to use GMP. To install gmpy, pip is used.
Searching for gmpy by pip, several kinds of gmpy are found. Their names and descriptions are shown below.

$ pip search gmpy
gmpy2                     - GMP/MPIR, MPFR, and MPC interface to Python 2.6+ and 3.x
gmpy                      - GMP or MPIR interface to Python 2.4+ and 3.x
gmpy_cffi                 - GMP CFFI wrapper

For the details of gmpy, please visit the URLs below.
For gmpy https://code.google.com/p/gmpy/
For gmpy2 https://pypi.python.org/pypi/gmpy2

The development of gmpy has been shifted from gmpy to gmpy2. If you are looking for the newest development of gmpy in general, please visit the site for gmpy2.

According to the webpage of GMPY, GMPY and GMPY2 are Python expansion modules, which support the fast multiple precision arithmetic. GMPY only supports the GMP library and provides fast multiple-precision integer and rational arithmetic. The limited mpf type from GMP is also supported. GHGMPY is no longer being maintained. On the other hand, GMPY2 supports the GMP library for integer and rational arithmetic but GMPY2 adds support for multiple-precision real and complex arithmetic as provided by the MPFR and MPC libraries. GMPY2 is being actively developed.

Installing gmpy on Mac OS X

In this article, since both MPFR and MPC are already installed on Mac, gmpy2 is going to be installed instead of gmpy.
This article also uses Mac OS X Mavericks 10.9.3.
To install gmpy2, pip is used rather than homebrew. To install pip on OS X, please look at this page.

$ sudo pip install gmpy2
Password:
Downloading/unpacking gmpy2
  Downloading gmpy2-2.0.3.zip (279kB): 279kB downloaded
  Running setup.py (path:/private/tmp/pip_build_root/gmpy2/setup.py) egg_info for package gmpy2
 
Installing collected packages: gmpy2
  Running setup.py install for gmpy2
    building 'gmpy2' extension
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv \
    -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes \
    -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -DWITHMPFR -DWITHMPC -I./src -I/usr/local/include \
    -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/gmpy2.c -o build/temp.macosx-10.9-intel-2.7/src/gmpy2.o
    In file included from src/gmpy2.c:508:
    ./src/gmpy_mpz_prp.c:1043:33: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
        for (j = mpz_sizeinbase(s,2)-1; j >= 1; j--) {
               ~ ~~~~~~~~~~~~~~~~~~~^~
    In file included from src/gmpy2.c:519:
    ./src/gmpy_mpz.c:1915:5: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        PARSE_ONE_MPZ_OPT_CLONG(&reps,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./src/gmpy_args.h:123:20: note: expanded from macro 'PARSE_ONE_MPZ_OPT_CLONG'
                *var = clong_From_Integer(PyTuple_GET_ITEM(args, 0)); \
                     ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from src/gmpy2.c:519:
    ./src/gmpy_mpz.c:1915:5: warning: implicit conversion loses integer precision: 'long' to 'int' [-Wshorten-64-to-32]
        PARSE_ONE_MPZ_OPT_CLONG(&reps,
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ./src/gmpy_args.h:137:20: note: expanded from macro 'PARSE_ONE_MPZ_OPT_CLONG'
                *var = clong_From_Integer(PyTuple_GET_ITEM(args, 1)); \
                     ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings generated.
    In file included from src/gmpy2.c:480:
    ./src/mpz_pylong.c:55:10: warning: shift count >= width of type [-Wshift-count-overflow]
      if ((x >> 32) != 0) { x >>= 32; cnt += 32; }
             ^  ~~
    ./src/mpz_pylong.c:55:27: warning: shift count >= width of type [-Wshift-count-overflow]
      if ((x >> 32) != 0) { x >>= 32; cnt += 32; }
                              ^   ~~
    2 warnings generated.
    cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.9-intel-2.7/src/gmpy2.o \
    -L/usr/local/lib -L/usr/local/lib -lgmp -lmpfr -lmpc -o build/lib.macosx-10.9-intel-2.7/gmpy2.so
    ld: warning: ignoring file /usr/local/lib/libgmp.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libgmp.dylib
    ld: warning: ignoring file /usr/local/lib/libmpfr.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libmpfr.dylib
    ld: warning: ignoring file /usr/local/lib/libmpc.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib/libmpc.dylib
     
Successfully installed gmpy2 
Cleaning up...

During the installation process, several warnings will appear. However, please ignore them. Regardless of these warnings, usually, the installation process will succeed.

To check whether gmpy2 is installed correctly or not, try execute a sample program. For instance, try execute gmpy2 and mpfr.

$ python
Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy2
>>> gmpy2.mpfr("1.2")
mpfr('1.2')
>>> gmpy2.sqrt(gmpy2.mpfr("3.2"))
mpfr('1.7888543819998317')
>>> gmpy2.sin(gmpy2.mpfr(".5"))
mpfr('0.47942553860420301')
>>>

The details of this sample program are described at the page of using gmp2 and mpfr.

Revision History

  • 2015/01/06 This article is initially uploaded

Front page   Edit Freeze Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   RSS of recent changes
Last-modified: 2015-01-06 (Tue) 06:47:46 (1053d)