Search code examples
pythonpython-2.7gccgmpy

gmpy2 installs but can't find libmpc.so.3


I want to use gmpy2 with python 2.7 but when I try to import it I get:

>>> import gmpy2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libmpc.so.3: cannot open shared object file: No such file or directory

I installed gmpy2 using pip: pip install -user gmpy2 and the install looks ok apart from saying

  Could not find .egg-info directory in install record for gmpy2

but after that it says that the install was a success.

I have installed MPC (1.0.3), GMP (6.1.1) and MPFR (3.1.4) and they all work, by which I mean I can call gcc foo.c -lmpc and gcc bar.c -lmpfr and the code compiles and works as expected. I've also got gmpy working using pip install. I think the problem will be to do with them not being installed in the default directories as I don't have sudo rights.

The directory where libmpc.so.3 is located is in the gcc call that pip spits out, I've also set CPATH and CPPFLAGS to look in my_prefix/include and LDFLAGS to look my_prefix/lib.

I don't really want to use the functionality from MPC so if there's a simple option to not install that part of gmpy2 I'd be happy with that.

I'm really confused, I've had it that pip fails to build a library and I've gone away and installed dependencies but normally once a library is passed pip it works.


Solution

  • I maintain gmpy2 and there are a couple of command line options that can be passed to setup.py that may help. I can't test the pip syntax right now but here are some options:

    --shared=/path/to/gmp,mpfr,mpc will configure gmpy2 to load the libraries from the specified directory.

    --static or --static=/path/to/gmp,mpfr,mpc will create a statically linked version of gmpy2 if the proper libraries can be found.

    You can also try a build using setup.py directly. It may produce better error messages. Again, untested command:

    python setup.py build_ext --static=/path/to/gmp,mpfr,mpc should compile a standalone, staticly linked gmpy2.so which will need to moved to the appropriate location.

    Update

    I've been able to test the options to pip.

    If you are trying to use versions of GMP, MPFR, and MPC that are not those provided by the Linux distribution, you will need to specify the location of the new files to the underlying setup.py that is called by pip. For example, I have updated versions installed locally in /home/case/local. The following command will configure gmpy2 to use those versions:

    pip install --install-option="--shared=/home/case/local" --user gmpy2
    

    To compile a statically linked version (for example, to simplify distribution to other systems in cluster), you should use the following:

    pip install --install-option="--static=/home/case/local" --user gmpy2
    

    setup.py will use the specified base directory to configure the correct INCLUDE path (/home/case/local/include) and runtime library path (/home/case/local/lib).