1

I'm making a course in freeCodeCamp about solidity and blockchain. I came to an issue trying to install web3 and can't figure out why. I've followed some of the steps but as I read on the messages on the terminal it doesn't seem the problem comes from python or pip. It seems it comes directly from the web3 package. Have been googling and have found more people with same issue but different error messages.

Here is the code:

zaesar@zaesar-X541UV:~/Escritorio/blockchain/demos/web3_py_simple_storage$ pip3 

install web3

This is what I get after writing pip3 install web3:

Defaulting to user installation because normal site-packages is not writeable
Collecting web3
   Using cached web3-5.28.0-py3-none-any.whl (499 kB)
Collecting jsonschema<4.0.0,>=3.2.0
  Using cached jsonschema-3.2.0-py2.py3-none-any.whl (56 kB)
Collecting lru-dict<2.0.0,>=1.1.6
  Using cached lru-dict-1.1.7.tar.gz (10 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: requests<3.0.0,>=2.16.0 in /home/zaesar/.local/lib/python3.9/site-packages (from web3) (2.27.1)
Collecting eth-typing<3.0.0,>=2.0.0
  Using cached eth_typing-2.3.0-py3-none-any.whl (6.2 kB)
Collecting eth-utils<2.0.0,>=1.9.5
  Using cached eth_utils-1.10.0-py3-none-any.whl (24 kB)
Collecting aiohttp<4,>=3.7.4.post0
  Using cached aiohttp-3.8.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB)
Collecting websockets<10,>=9.1
  Using cached websockets-9.1-cp39-cp39-manylinux2010_x86_64.whl (102 kB)
Collecting ipfshttpclient==0.8.0a2
  Using cached ipfshttpclient-0.8.0a2-py3-none-any.whl (82 kB)
Collecting hexbytes<1.0.0,>=0.1.0
  Using cached hexbytes-0.2.2-py3-none-any.whl (6.1 kB)
Collecting eth-abi<3.0.0,>=2.0.0b6
  Using cached eth_abi-2.1.1-py3-none-any.whl (27 kB)
Collecting eth-hash[pycryptodome]<1.0.0,>=0.2.0
  Using cached eth_hash-0.3.2-py3-none-any.whl (8.8 kB)
Collecting protobuf<4,>=3.10.0
  Using cached protobuf-3.19.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB)
Collecting eth-account<0.6.0,>=0.5.7
  Using cached eth_account-0.5.7-py3-none-any.whl (101 kB)
Collecting multiaddr>=0.0.7
  Using cached multiaddr-0.0.9-py2.py3-none-any.whl (16 kB)
Collecting async-timeout<5.0,>=4.0.0a3
  Using cached async_timeout-4.0.2-py3-none-any.whl (5.8 kB)
Collecting multidict<7.0,>=4.5
  Using cached multidict-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)
Collecting attrs>=17.3.0
  Using cached attrs-21.4.0-py2.py3-none-any.whl (60 kB)
Collecting frozenlist>=1.1.1
  Using cached frozenlist-1.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (156 kB)
Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/zaesar/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4.post0->web3) (2.0.12)
Collecting yarl<2.0,>=1.0
  Using cached yarl-1.7.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (304 kB)
Collecting aiosignal>=1.1.2
  Using cached aiosignal-1.2.0-py3-none-any.whl (8.2 kB)
Collecting parsimonious<0.9.0,>=0.8.0
  Using cached parsimonious-0.8.1-py3-none-any.whl
Collecting eth-keyfile<0.6.0,>=0.5.0
  Using cached eth_keyfile-0.5.1-py3-none-any.whl (8.3 kB)
Collecting rlp<3,>=1.0.0
  Using cached rlp-2.0.1-py2.py3-none-any.whl (20 kB)
Collecting bitarray<1.3.0,>=1.2.1
  Using cached bitarray-1.2.2.tar.gz (48 kB)
  Preparing metadata (setup.py) ... done
Collecting eth-keys<0.4.0,>=0.3.4
  Using cached eth_keys-0.3.4-py3-none-any.whl (21 kB)
Collecting eth-rlp<2,>=0.1.2
  Using cached eth_rlp-0.3.0-py3-none-any.whl (5.0 kB)
Collecting pycryptodome<4,>=3.6.6
  Using cached pycryptodome-3.14.1-cp35-abi3-manylinux2010_x86_64.whl (2.0 MB)
Collecting cytoolz<1.0.0,>=0.10.1
  Using cached cytoolz-0.11.2.tar.gz (481 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: setuptools in /home/zaesar/.local/lib/python3.9/site-packages (from jsonschema<4.0.0,>=3.2.0->web3) (61.2.0)
Requirement already satisfied: six>=1.11.0 in /usr/lib/python3/dist-packages (from jsonschema<4.0.0,>=3.2.0->web3) (1.11.0)
Collecting pyrsistent>=0.14.0
  Using cached pyrsistent-0.18.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (115 kB)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests<3.0.0,>=2.16.0->web3) (2018.1.18)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3/dist-packages (from requests<3.0.0,>=2.16.0->web3) (1.22)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests<3.0.0,>=2.16.0->web3) (2.6)
Collecting toolz>=0.8.0
  Using cached toolz-0.11.2-py3-none-any.whl (55 kB)
Collecting eth-rlp<2,>=0.1.2
  Using cached eth_rlp-0.2.1-py3-none-any.whl (5.0 kB)
Requirement already satisfied: netaddr in /home/zaesar/.local/lib/python3.9/site-packages (from multiaddr>=0.0.7->ipfshttpclient==0.8.0a2->web3) (0.8.0)
Requirement already satisfied: varint in /home/zaesar/.local/lib/python3.9/site-packages (from multiaddr>=0.0.7->ipfshttpclient==0.8.0a2->web3) (1.0.2)
Collecting base58
  Using cached base58-2.1.1-py3-none-any.whl (5.6 kB)
Building wheels for collected packages: lru-dict, bitarray, cytoolz
  Building wheel for lru-dict (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [12 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'lru' extension
      creating build
      creating build/temp.linux-x86_64-3.9
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python3.9 -c lru.c -o build/temp.linux-x86_64-3.9/lru.o
      lru.c:1:10: fatal error: Python.h: No existe el archivo o el directorio
       #include <Python.h>
                ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for lru-dict
  Running setup.py clean for lru-dict
  Building wheel for bitarray (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [20 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.9
      creating build/lib.linux-x86_64-3.9/bitarray
      copying bitarray/__init__.py -> build/lib.linux-x86_64-3.9/bitarray
      copying bitarray/util.py -> build/lib.linux-x86_64-3.9/bitarray
      copying bitarray/test_util.py -> build/lib.linux-x86_64-3.9/bitarray
      copying bitarray/test_bitarray.py -> build/lib.linux-x86_64-3.9/bitarray
      running build_ext
      building 'bitarray._bitarray' extension
      creating build/temp.linux-x86_64-3.9
      creating build/temp.linux-x86_64-3.9/bitarray
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python3.9 -c bitarray/_bitarray.c -o build/temp.linux-x86_64-3.9/bitarray/_bitarray.o
      bitarray/_bitarray.c:12:10: fatal error: Python.h: No existe el archivo o el directorio
       #include "Python.h"
                ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for bitarray
  Running setup.py clean for bitarray
  Building wheel for cytoolz (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [56 lines of output]
      ALERT: Cython not installed.  Building without Cython.
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.9
      creating build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/compatibility.py -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/__init__.py -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/_version.py -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/_signatures.py -> build/lib.linux-x86_64-3.9/cytoolz
      creating build/lib.linux-x86_64-3.9/cytoolz/curried
      copying cytoolz/curried/__init__.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
      copying cytoolz/curried/operator.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
      copying cytoolz/curried/exceptions.py -> build/lib.linux-x86_64-3.9/cytoolz/curried
      copying cytoolz/dicttoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/utils.pyx -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/functoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/recipes.pyx -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/itertoolz.pyx -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/functoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/dicttoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/__init__.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/itertoolz.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/cpython.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/utils.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      copying cytoolz/recipes.pxd -> build/lib.linux-x86_64-3.9/cytoolz
      creating build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_docstrings.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_doctests.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_none_safe.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_signatures.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_compatibility.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_recipes.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_serialization.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_itertoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_curried_toolzlike.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_tlz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_utils.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/dev_skip_test.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_curried.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_inspect_args.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_dev_skip_test.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_functoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_dicttoolz.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      copying cytoolz/tests/test_embedded_sigs.py -> build/lib.linux-x86_64-3.9/cytoolz/tests
      running build_ext
      building 'cytoolz.dicttoolz' extension
      creating build/temp.linux-x86_64-3.9
      creating build/temp.linux-x86_64-3.9/cytoolz
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python3.9 -c cytoolz/dicttoolz.c -o build/temp.linux-x86_64-3.9/cytoolz/dicttoolz.o
      cytoolz/dicttoolz.c:19:10: fatal error: Python.h: No existe el archivo o el directorio
       #include "Python.h"
                ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cytoolz
  Running setup.py clean for cytoolz
Failed to build lru-dict bitarray cytoolz
Installing collected packages: lru-dict, bitarray, websockets, 
toolz, pyrsistent, pycryptodome, protobuf, parsimonious, 
multidict, hexbytes, frozenlist, eth-typing, eth-hash, base58, 
attrs, async-timeout, yarl, multiaddr, jsonschema, cytoolz, 
aiosignal, ipfshttpclient, eth-utils, aiohttp, rlp, eth-keys, eth-abi, eth-rlp, eth-keyfile, eth-account, web3
  Running setup.py install for lru-dict ... error
  error: subprocess-exited-with-error

      × Running setup.py install for lru-dict did not run successfully.
      │ exit code: 1
      ╰─> [14 lines of output]
          running install
          /home/zaesar/.local/lib/python3.9/site- 
   packages/setuptools/command/install.py:34: 
SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
    warnings.warn(
  running build
  running build_ext
  building 'lru' extension
      creating build
      creating build/temp.linux-x86_64-3.9
      x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python3.9 -c lru.c -o build/temp.linux-x86_64-3.9/lru.o
      lru.c:1:10: fatal error: Python.h: No existe el archivo o el directorio
       #include <Python.h>
                ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit 
code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a 
problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lru-dict

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

As it is written on the last lines. It doesn't seem a problem of python or pip. It is more a problem from the package itself.

I'm struggling trying to figure out what could be the problem and how can I solve it. Any help will be really appreciate it.

1 Answer 1

1

Origin of the problem:

lru.c:1:10: fatal error: Python.h: No such file or directory
                1 | #include <Python.h>

Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.

You have to apply:

sudo apt-get install python-dev  # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

Please see the answer for fatal error: Python.h: No such file or directory for details.

5
  • Thanks for the response! What you mean with package manager
    – Zaesar
    Apr 2, 2022 at 17:56
  • @Zaesar ubuntu.com/server/docs/package-management . Are you using Ubuntu or macOS?
    – alper
    Apr 2, 2022 at 23:54
  • I'm using Ubuntu
    – Zaesar
    Apr 5, 2022 at 9:46
  • Than you should install python-dev and python3-dev using apt-get
    – alper
    Apr 5, 2022 at 10:52
  • Appreciate your comment
    – Zaesar
    Apr 5, 2022 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.