Need Help installing GMPY2 2.0.8 into my PyCharm venv

Using PyCharm CE 2021.1

OS = Ubuntu Linux 18.04

Python 3.9

Package to Install = GMPY2    version = 2.0.8

Actions:

1- Opened terminal within PyCharm in virtual environment

2- Did source venv/bin/activate  (worked)
3- Did pip install wheel 

Requirement already satisfied: wheel in ./venv/lib/python3.9/site-packages (0.36.2)

4- Did pip install -r requirements.txt  (failed with errors) (I tried many things; nothing worked; totally stumped!) here is the result:

Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.4"' don't match your environment
Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.5"' don't match your environment
Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.6"' don't match your environment
Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.7"' don't match your environment
Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.8"' don't match your environment
Ignoring gmpy2: markers 'platform_system == "Windows" and python_version == "3.9"' don't match your environment
Requirement already satisfied: wheel in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 1)) (0.36.2)
Collecting gmpy2
Using cached gmpy2-2.0.8.zip (280 kB)
Requirement already satisfied: matplotlib in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 9)) (3.4.2)
Requirement already satisfied: PyQt5 in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 10)) (5.15.4)
Requirement already satisfied: kiwisolver>=1.0.1 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (1.3.1)
Requirement already satisfied: pyparsing>=2.2.1 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (2.4.7)
Requirement already satisfied: cycler>=0.10 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (0.10.0)
Requirement already satisfied: numpy>=1.16 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (1.20.3)
Requirement already satisfied: pillow>=6.2.0 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (8.2.0)
Requirement already satisfied: python-dateutil>=2.7 in ./venv/lib/python3.9/site-packages (from matplotlib->-r requirements.txt (line 9)) (2.8.1)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from cycler>=0.10->matplotlib->-r requirements.txt (line 9)) (1.11.0)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in ./venv/lib/python3.9/site-packages (from PyQt5->-r requirements.txt (line 10)) (12.9.0)
Requirement already satisfied: PyQt5-Qt5>=5.15 in ./venv/lib/python3.9/site-packages (from PyQt5->-r requirements.txt (line 10)) (5.15.2)
Building wheels for collected packages: gmpy2
Building wheel for gmpy2 (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-78_9y6xy
cwd: /tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/
Complete output (13 lines):
running bdist_wheel
running build
running build_ext
building 'gmpy2' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITHMPFR -DWITHMPC -I/home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/include -I/usr/include/python3.9 -c src/gmpy2.c -o build/temp.linux-x86_64-3.9/src/gmpy2.o
src/gmpy2.c:404:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Failed building wheel for gmpy2
Running setup.py clean for gmpy2
Failed to build gmpy2
Installing collected packages: gmpy2
Running setup.py install for gmpy2 ... error
ERROR: Command errored out with exit status 1:
command: /home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-0524fvnm/install-record.txt --single-version-externally-managed --compile --install-headers /home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/include/site/python3.9/gmpy2
cwd: /tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/
Complete output (13 lines):
running install
running build
running build_ext
building 'gmpy2' extension
creating build
creating build/temp.linux-x86_64-3.9
creating build/temp.linux-x86_64-3.9/src
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DWITHMPFR -DWITHMPC -I/home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/include -I/usr/include/python3.9 -c src/gmpy2.c -o build/temp.linux-x86_64-3.9/src/gmpy2.o
src/gmpy2.c:404:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"'; __file__='"'"'/tmp/pip-install-g7kpv8x3/gmpy2_1d139a1c147041ca8a89d2bf9e271d98/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-0524fvnm/install-record.txt --single-version-externally-managed --compile --install-headers /home/nexus/Documents/Qt_Projects/PyQt_Projects/Projects/Chessmatic_Trainer/venv/include/site/python3.9/gmpy2 Check the logs for full command output.

0
1 comment

I managed to solve the problem!

I used 'sudo apt install' from within my venv to install all the libs; then use 'pip install' to install the python module into the venv.
 
The problems stemmed from misunderstanding how ‘pip install’ and ‘sudo apt install’ work when executed within a virtual environment; was wrongly using pip for everything. 
 
My impression was 'sudo apt' was for operating outside venv, and pip was for operating inside venv, so I never considered 'sudo apt'.  
 
0

Please sign in to leave a comment.