3

EDIT: I'm using Win 10 and Ubuntu from the app store

I have tried to install gmpy2 by using:

apt-get install libgmp-dev
apt-get install libmpfr-dev
apt-get install libmpc-dev

and also downloaded MPIR and compiled it. however using pip install gmpy2 still gives me the error

c:\users\gypsyzz\appdata\local\temp\pip-install-l2hlf7q4\gmpy2\src\gmpy.h(104): fatal error C1083: Cannot open include file: 'mpir.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.13.26128\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

in addition, i found that using the prebuilt wheel at https://www.lfd.uci.edu/~gohlke/pythonlibs/ does not give me any functions.

import gmpy2
from gmpy2 import mpz,mpq,mpfr,mpc
gmpy2.conjugate(mpc())
Traceback (most recent call last):

File "<ipython-input-18-2d51a42bda9a>", line 1, in <module>
gmpy2.conjugate(mpc())

AttributeError: module 'gmpy2' has no attribute 'conjugate'

I'm more certain that I have understood the functions wrongly for the last part, so please let me know the correct syntax.

gypsyzz
  • 43
  • 1
  • 1
  • 6
  • You seem to be mixing up linux and windows... – Marc Glisse May 24 '18 at 19:23
  • @MarcGlisse Yes there's some mixing up. In Win 10 you can open ubuntu (not virtual client) with app store, and have an command prompt interface. I'm not sure how much of the software installations are shared to windows. I have an Ubuntu setup alongside now seeing how frustrating the situation is. – gypsyzz May 25 '18 at 07:50
  • **No software** is shared between ubuntu and windows. If you install GMP on linux, it is useless to python on windows. – Marc Glisse May 25 '18 at 10:27
  • well then that explains, I'll stick to ubuntu for work then. – gypsyzz May 25 '18 at 11:32
  • And conjugate() is a method of the mpc type; not a function of the gmpy2 module. The following should work: gmpy2.mpc("1+2j").conjugate() – casevh May 25 '18 at 16:31
  • @casevh yes I've tried that. but it crashes the ipython kernal. I'm using Ubuntu 18.04 python 3.6.5 and spyder3. – gypsyzz May 25 '18 at 21:06
  • using python command gives the same problem of crashing. code is `import numpy as np import gmpy2 from gmpy2 import mpc mpc('1+2j').conjugate()` and error is: Segmentation fault (core dumped) – gypsyzz May 26 '18 at 08:36
  • I can confirm the the bug. I'll work on a fix. Tracking at https://github.com/aleaxit/gmpy/issues/194 – casevh May 26 '18 at 14:06

3 Answers3

11

This is a bug in gmpy2 2.0.x series. It has been fixed in the currently development version. gmpy2 2.1.0a2 is available on PyPi but is hidden. The following commands will install it in a user-specific directory. Python will load modules from the user-specific directory first so the new version will shadow the provided version.

sudo apt install libmpc-dev
sudo apt install python3-pip
pip3 install --user gmpy2==2.1.0a2

The new version should be backwards compatible with the old version. But if you encounter any issues, you can remove the user-specific version as follows.

pip3 uninstall gmpy2==2.1.0a2

casevh
  • 11,093
  • 1
  • 24
  • 35
0

For me this worked:

apt-get install libgmp3-dev # For Ubuntu, might vary by Linux distro
pip3 install gmpy --user
jkmartindale
  • 523
  • 2
  • 9
  • 22
0

If you have Anaconda installed on your system, then the simplest way of installing it would be using conda itself which will take care of all the dependencies that gmpy2 needs. The command is: conda install gmpy2