Web3.py – Fixing Web3 Python Installation Issues: Include “Python.h” Error and GCC Command Failures

pythonweb3.py

I was trying to setup a new virtual environment for my project. I did not have any issues the last 5 Months installing web3, but today I just cant get it to work 🙁

pip install web3==4.1.0
Collecting web3==4.1.0
  Using cached https://files.pythonhosted.org/packages/4c/a2/9f2cf0fc2c7938871586061491f7be9a2a67028dad091e01bf781195eb87/web3-4.1.0-py3-none-any.whl
Collecting requests<3.0.0,>=2.16.0 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting hexbytes<1.0.0,>=0.1.0 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/18/bd/21697d93ee2153c8c12253262b740f571e94341d4cee411504032fff3f56/hexbytes-0.1.0-py3-none-any.whl
Collecting eth-abi<2,>=1.0.0 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/e9/ef/5af786a32ae7ac3aece6489400ea2cee6b2ede7a7b3955e6f55a59442d12/eth_abi-1.3.0-py3-none-any.whl
Collecting eth-utils<2.0.0,>=1.0.1 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/91/c8/0ef940843b45377a8d150c94fa8d147607180e89f5d604d3a2be646d9d96/eth_utils-1.4.1-py3-none-any.whl
Collecting lru-dict<2.0.0,>=1.1.6 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/00/a5/32ed6e10246cd341ca8cc205acea5d208e4053f48a4dced2b1b31d45ba3f/lru-dict-1.1.6.tar.gz
Collecting websockets>=4.0.1 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/43/71/8bfa882b9c502c36e5c9ef6732969533670d2b039cbf95a82ced8f762b80/websockets-7.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting eth-account==0.1.0-alpha.2 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/7d/4e/46fffb1bd4e2da97cc3e11120b465b48f14480b6e1fb6dd8843d1f5912ab/eth_account-0.1.0a2-py3-none-any.whl
Collecting eth-hash[pycryptodome] (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/0d/d8/0f0c8d4ccaa4c8d25524fd1ed9f5c6d9551b52b74b973f338de3f0a23111/eth_hash-0.2.0-py3-none-any.whl
Collecting cytoolz<1.0.0,>=0.9.0 (from web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/36/f4/9728ba01ccb2f55df9a5af029b48ba0aaca1081bbd7823ea2ee223ba7a42/cytoolz-0.9.0.1.tar.gz
Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.16.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests<3.0.0,>=2.16.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests<3.0.0,>=2.16.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests<3.0.0,>=2.16.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/9f/e0/accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a/certifi-2018.11.29-py2.py3-none-any.whl
Collecting parsimonious<0.9.0,>=0.8.0 (from eth-abi<2,>=1.0.0->web3==4.1.0)
Collecting eth-typing<3.0.0,>=2.0.0 (from eth-abi<2,>=1.0.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/88/df/19e17ca63aa0285ef0c2e95231f2f6a8d99a69ee58817c22b6b417067460/eth_typing-2.0.0-py3-none-any.whl
Collecting eth-rlp<1,>=0.1.0a2 (from eth-account==0.1.0-alpha.2->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/56/4b/b309fb44dd9bb975e84f3d626392eec1eeed0108e55a51cd7dd8956a73ad/eth_rlp-0.1.2-py3-none-any.whl
Collecting eth-keys<0.3.0,>=0.2.0b1 (from eth-account==0.1.0-alpha.2->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/9b/96/bec507291a2ecac65358b4485282ce02e8c0cdd30980a232791b355a1f5b/eth_keys-0.2.0b3-py3-none-any.whl
Collecting attrdict<3,>=2.0.0 (from eth-account==0.1.0-alpha.2->web3==4.1.0)
Collecting eth-keyfile<0.6.0,>=0.5.0 (from eth-account==0.1.0-alpha.2->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/eb/a5/3615d100b62fbf20fe5d5c0d1d4d7326eac861d260b0cd2a36af2bf8ccb1/eth_keyfile-0.5.1-py3-none-any.whl
Collecting pycryptodome<4,>=3.6.6; extra == "pycryptodome" (from eth-hash[pycryptodome]->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/ab/bc/589fbae48c0969719f28b862d979f8e9d4d1e08bb7f68ad7a495b1ba2d54/pycryptodome-3.7.2-cp36-cp36m-manylinux1_x86_64.whl
Collecting toolz>=0.8.0 (from cytoolz<1.0.0,>=0.9.0->web3==4.1.0)
Collecting six>=1.9.0 (from parsimonious<0.9.0,>=0.8.0->eth-abi<2,>=1.0.0->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting rlp<2,>=0.6.0 (from eth-rlp<1,>=0.1.0a2->eth-account==0.1.0-alpha.2->web3==4.1.0)
  Using cached https://files.pythonhosted.org/packages/98/88/6276aea1ded17ee6db53cc03a80bebdd9c71291dd29e65582314b4bc92fd/rlp-1.0.3-py2.py3-none-any.whl
Building wheels for collected packages: lru-dict, cytoolz
  Running setup.py bdist_wheel for lru-dict ... error
  Complete output from command /home/debbi/Documents/env/eth/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-flkwezpc/lru-dict/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-iklwwj6r --python-tag cp36:
  running bdist_wheel
  running build
  running build_ext
  building 'lru' extension
  creating build
  creating build/temp.linux-x86_64-3.6
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/debbi/Documents/env/eth/include/python3.6m -c lru.c -o build/temp.linux-x86_64-3.6/lru.o
  lru.c:1:10: fatal error: Python.h: No such file or directory
   #include <Python.h>
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for lru-dict
  Running setup.py clean for lru-dict
  Running setup.py bdist_wheel for cytoolz ... error
  Complete output from command /home/debbi/Documents/env/eth/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-flkwezpc/cytoolz/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-q1ktdq50 --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/__init__.py -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/_version.py -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/_signatures.py -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/utils_test.py -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/compatibility.py -> build/lib.linux-x86_64-3.6/cytoolz
  creating build/lib.linux-x86_64-3.6/cytoolz/curried
  copying cytoolz/curried/__init__.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
  copying cytoolz/curried/operator.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
  copying cytoolz/curried/exceptions.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
  copying cytoolz/utils.pyx -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/itertoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/functoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/dicttoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/recipes.pyx -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/recipes.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/__init__.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/utils.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/cpython.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/dicttoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/itertoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  copying cytoolz/functoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
  creating build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/dev_skip_test.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_docstrings.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_utils.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_signatures.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_none_safe.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_embedded_sigs.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_recipes.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_curried.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_inspect_args.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_dev_skip_test.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_compatibility.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_tlz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_serialization.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_functoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_doctests.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_dicttoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_itertoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  copying cytoolz/tests/test_curried_toolzlike.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
  running build_ext
  building 'cytoolz.dicttoolz' extension
  creating build/temp.linux-x86_64-3.6
  creating build/temp.linux-x86_64-3.6/cytoolz
  x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/debbi/Documents/env/eth/include/python3.6m -c cytoolz/dicttoolz.c -o build/temp.linux-x86_64-3.6/cytoolz/dicttoolz.o
  cytoolz/dicttoolz.c:17:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for cytoolz
  Running setup.py clean for cytoolz
Failed to build lru-dict cytoolz
Installing collected packages: chardet, urllib3, idna, certifi, requests, eth-typing, toolz, cytoolz, pycryptodome, eth-hash, eth-utils, hexbytes, six, parsimonious, eth-abi, lru-dict, websockets, rlp, eth-rlp, eth-keys, attrdict, eth-keyfile, eth-account, web3
  Running setup.py install for cytoolz ... error
    Complete output from command /home/debbi/Documents/env/eth/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-flkwezpc/cytoolz/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-kqcaqzcr/install-record.txt --single-version-externally-managed --compile --install-headers /home/debbi/Documents/env/eth/include/site/python3.6/cytoolz:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/__init__.py -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/_version.py -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/_signatures.py -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/utils_test.py -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/compatibility.py -> build/lib.linux-x86_64-3.6/cytoolz
    creating build/lib.linux-x86_64-3.6/cytoolz/curried
    copying cytoolz/curried/__init__.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
    copying cytoolz/curried/operator.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
    copying cytoolz/curried/exceptions.py -> build/lib.linux-x86_64-3.6/cytoolz/curried
    copying cytoolz/utils.pyx -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/itertoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/functoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/dicttoolz.pyx -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/recipes.pyx -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/recipes.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/__init__.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/utils.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/cpython.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/dicttoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/itertoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    copying cytoolz/functoolz.pxd -> build/lib.linux-x86_64-3.6/cytoolz
    creating build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/dev_skip_test.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_docstrings.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_utils.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_signatures.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_none_safe.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_embedded_sigs.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_recipes.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_curried.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_inspect_args.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_dev_skip_test.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_compatibility.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_tlz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_serialization.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_functoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_doctests.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_dicttoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_itertoolz.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    copying cytoolz/tests/test_curried_toolzlike.py -> build/lib.linux-x86_64-3.6/cytoolz/tests
    running build_ext
    building 'cytoolz.dicttoolz' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/cytoolz
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -I/home/debbi/Documents/env/eth/include/python3.6m -c cytoolz/dicttoolz.c -o build/temp.linux-x86_64-3.6/cytoolz/dicttoolz.o
    cytoolz/dicttoolz.c:17:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/debbi/Documents/env/eth/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-flkwezpc/cytoolz/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-kqcaqzcr/install-record.txt --single-version-externally-managed --compile --install-headers /home/debbi/Documents/env/eth/include/site/python3.6/cytoolz" failed with error code 1 in /tmp/pip-install-flkwezpc/cytoolz/

I tried using web3 and web3==4.1.0, its just not working 🙁

Thank you for your time.

Best Answer

I forgot to install

sudo apt-get install python3-dev
sudo apt-get install libssl-dev

mybad.

Related Topic