Search code examples
pythonsetuptoolspython-poetrypyproject.tomlpython-3.11

Python poetry install fails on typed-ast (1.5.4). How to overcome the obstacle and install the package?


I tried to install the package using pip:

pip wheel --use-pep517 "typed-ast (==1.5.4)"

but it falls in the same place.

What's the general approach when you walk into such kind of problems?

I've found this thread, which seemed to be helpful, but it wasn't

(.venv) ➜  src git:(develop) ✗ poetry install
Installing dependencies from lock file
Warning: poetry.lock is not consistent with pyproject.toml. You may be getting improper dependencies. Run `poetry lock [--no-update]` to fix it.

Package operations: 24 installs, 0 updates, 0 removals

  • Installing typed-ast (1.5.4): Failed

  ChefBuildError

  Backend subprocess exited when trying to invoke build_wheel
  
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-cpython-311
  creating build/lib.linux-x86_64-cpython-311/typed_ast
  copying typed_ast/__init__.py -> build/lib.linux-x86_64-cpython-311/typed_ast
  copying typed_ast/ast27.py -> build/lib.linux-x86_64-cpython-311/typed_ast
  copying typed_ast/conversions.py -> build/lib.linux-x86_64-cpython-311/typed_ast
  copying typed_ast/ast3.py -> build/lib.linux-x86_64-cpython-311/typed_ast
  creating build/lib.linux-x86_64-cpython-311/typed_ast/tests
  copying ast3/tests/test_basics.py -> build/lib.linux-x86_64-cpython-311/typed_ast/tests
  running build_ext
  building '_ast27' extension
  creating build/temp.linux-x86_64-cpython-311
  creating build/temp.linux-x86_64-cpython-311/ast27
  creating build/temp.linux-x86_64-cpython-311/ast27/Custom
  creating build/temp.linux-x86_64-cpython-311/ast27/Parser
  creating build/temp.linux-x86_64-cpython-311/ast27/Python
  x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Iast27/Include -I/tmp/tmpwhqt9erw/.venv/include -I/usr/include/python3.11 -c ast27/Custom/typed_ast.c -o build/temp.linux-x86_64-cpython-311/ast27/Custom/typed_ast.o
  ast27/Custom/typed_ast.c:1:10: fatal error: Python.h: No such file or directory
      1 | #include "Python.h"
        |          ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
  

  at ~/c/mrnet/mrnet_backend/.venv/lib/python3.11/site-packages/poetry/installation/chef.py:152 in _prepare
      148│ 
      149│                 error = ChefBuildError("\n\n".join(message_parts))
      150│ 
      151│             if error is not None:
    → 152│                 raise error from None
      153│ 
      154│             return path
      155│ 
      156│     def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:

Note: This error originates from the build backend, and is likely not a problem with poetry but with typed-ast (1.5.4) not supporting PEP 517 builds. You can verify this by running 'pip wheel --use-pep517 "typed-ast (==1.5.4)"'.

(.venv) ➜  src git:(develop) ✗ pip wheel --use-pep517 "typed-ast (==1.5.4)"
Collecting typed-ast==1.5.4
  Using cached typed_ast-1.5.4.tar.gz (252 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: typed-ast
  Building wheel for typed-ast (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for typed-ast (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-311
      creating build/lib.linux-x86_64-cpython-311/typed_ast
      copying typed_ast/__init__.py -> build/lib.linux-x86_64-cpython-311/typed_ast
      copying typed_ast/ast27.py -> build/lib.linux-x86_64-cpython-311/typed_ast
      copying typed_ast/conversions.py -> build/lib.linux-x86_64-cpython-311/typed_ast
      copying typed_ast/ast3.py -> build/lib.linux-x86_64-cpython-311/typed_ast
      creating build/lib.linux-x86_64-cpython-311/typed_ast/tests
      copying ast3/tests/test_basics.py -> build/lib.linux-x86_64-cpython-311/typed_ast/tests
      running build_ext
      building '_ast27' extension
      creating build/temp.linux-x86_64-cpython-311
      creating build/temp.linux-x86_64-cpython-311/ast27
      creating build/temp.linux-x86_64-cpython-311/ast27/Custom
      creating build/temp.linux-x86_64-cpython-311/ast27/Parser
      creating build/temp.linux-x86_64-cpython-311/ast27/Python
      x86_64-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -Iast27/Include -I/home/yevt/c/mrnet/mrnet_backend/.venv/include -I/usr/include/python3.11 -c ast27/Custom/typed_ast.c -o build/temp.linux-x86_64-cpython-311/ast27/Custom/typed_ast.o
      ast27/Custom/typed_ast.c:1:10: fatal error: Python.h: No such file or directory
          1 | #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 typed-ast
Failed to build typed-ast
ERROR: Failed to build one or more wheels
(.venv) ➜  src git:(develop) ✗ pip wheel --use-pep517 "typed-ast (==1.5.4)"

  • ubuntu 22.04
  • gcc 11.3.0
  • python 3.11

Solution

  • Do you install python3.11-dev?

    sudo apt install -y python3.11-dev
    

    or packages for compiling

    sudo apt install -y build-essential libssl-dev libffi-dev python3.11-dev