Python cannot locate the gmpy library

Python cannot locate the gmpy library … here is a solution to the problem.

Python cannot locate the gmpy library

I want to use a python script that imports gmpy. However, Python always tells me:

ImportError: There is no module named "gmpy"

I’m on Ubuntu 14.04 i686 and I’m trying to install gmpy:: in various ways

  1. sudo pip install gmpy
  2. sudo pip install gmpy2
  3. sudo apt-get install python-gmpy*
  4. sudo apt-get install python2.7-gmpy*
  5. sudo apt-get install python3-gmpy*
  6. I also

  7. followed the official instructions on building gmpy from source (for this reason, I also compiled MPC, MPFR, and GMP from source).

Apparently I’m using python 3.4.0:

$ python
$ Python 3.4.0 (default, Apr 11 2014, 13:05:18)
  [GCC 4.8.2] on linux

What am I missing so that python can’t find the gmpy library?

Solution

Either of the following solutions resolves the issue:

sudo pip3 install gmpy (because I’m using python3, I executed the wrong pip).

or

$python2.7 script.py (or simply use the python2 interpreter).

Related Problems and Solutions