3

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

ImportError: No module named 'gmpy'

I am on Ubuntu 14.04 i686 and I tried to install gmpy over 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 followed the officiel instruction on building gmpy from source (I also compiled MPC, MPFR, and GMP from source for this reason).

Obviously I am 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 such that python is not able to find the gmpy libs?

Richard Laurant
  • 647
  • 1
  • 8
  • 21
  • Was any of the attempted install methods successful? – Tim Jun 03 '14 at 13:38
  • is pip command for 2.7 or 3.4? – Padraic Cunningham Jun 03 '14 at 13:41
  • Sorry,I forgot to mention: all of them were successful. – Richard Laurant Jun 03 '14 at 13:42
  • have you tried sudo pip-3.4 install gmpy? – Padraic Cunningham Jun 03 '14 at 13:44
  • How did you get your default python to be version 3.4.0? The default version of python on Ubuntu 14.04 should be 2.7.6, and AFAIK, it can not be changed without causing problems -- like `sudo apt-get install python-*` to install stuff in a place that your (new) default python will not find. – unutbu Jun 03 '14 at 13:53
  • Also note that every pip executable is tied to one distribution of python. If you type `which pip` and look at the shebang line inside the `pip` script, you'll see which python executable it is tied to. For `sudo pip install gmpy2` to work, you need to install a pip which is "tied" to your python 3.4.0 executable. You might already have such a pip installed. It would help to know how you installed the 3.4.0 executable. – unutbu Jun 03 '14 at 14:02

2 Answers2

3

Any of the following solutions solved the problem:

sudo pip3 install gmpy (I executed the wrong pip as I am using python3)

or

$ python2.7 script.py (Or simply use python2 interpreter)

Richard Laurant
  • 647
  • 1
  • 8
  • 21
  • I've had issues with too many versions of pip so I use `pythonXYZ -m pip ...` which executes the pip module for python XYZ. – R.Mckemey Jan 31 '17 at 13:24
1
  • apt-get -f install
  • pip2 install gmpy

Done.