cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No such file or directory

    cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No such file or directory
     19 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for cytoolz

I'm using this:

   (venv) root@x-System-Product-Name:~# pypy3 --version
Python 3.6.9 (7.3.1+dfsg-4, Apr 22 2020, 05:15:29)
[PyPy 7.3.1 with GCC 9.3.0]

I had problems with web3 installation, was able to solve up to the point of packages lru-dict, bitarray, and cytoolz. Those are the showstoppers...

I tried those solutions from the Internet, they didn't work for me:

pip3 install wheel

sudo apt-get install python-dev 
sudo apt-get install python3-dev
sudo apt-get install libevent-dev
sudo apt-get install libblas-dev libatlas-base-dev

python -m venv --upgrade ./venv

sudo apt-get install python3-dev
sudo apt install libpython3.x-dev


dpkg --add-architecture i386
apt-get update
apt-get install libssl-dev:i386

sudo apt-get install openssl libssl-dev

pip3 install --upgrade pip

sudo apt-get install libpcap-dev libpq-dev

ERROR persists, in the same form, with the exact same packages.

I also tried installing from manually downloaded files, still the same 'failed building wheel' error.

Tried installing GCC, and some other random ideas were tried and failed.

... what a bug-fest.

SOLVED:

This tutorial worked: https://blog.ducthinh.net/gcc-no-such-file-python-h/

However, still the installation needs work done on it - I'm getting this error about cytoolz package (which is I decided to not mark this solved).

ImportError: /usr/local/lib/pypy3.6/dist-packages/cytoolz/itertoolz.pypy36-pp73-x86_64-linux-gnu.so: undefined symbol: PyExc_SystemError

You need the version of Python.h and associated files for PyPy, not the one from CPython. That's usually in a package called something like pypy3-dev.


It was solved in my case by installing the appropriate python3-dev package corresponding to the python version in my virtualenv:

sudo apt install python3.10-dev

I find this cleaner than messing with python.h files.