Skip to content

[Linux] fails to build - missing Python.h? #1889

Closed

Description

@aaronsdevera

Platform

  • Linux
  • psutil-5.7.3
  • Python 3.8

Bug description

Getting this error on linux (elementary OS, based on ubuntu 18.04 LTS) with architecture intel i7-4700MQ CPU @ 2.40
Seems to be related to a missing header file?

Error:

running build_ext
    building 'psutil._psutil_linux' extension
    creating build/temp.linux-x86_64-3.8
    creating build/temp.linux-x86_64-3.8/psutil
    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 -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_LINUX=1 -I/usr/include/python3.8 -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.8/psutil/_psutil_common.o
    psutil/_psutil_common.c:9: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
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_dk0cwo0/psutil_968214155e33476e887f69a214c0bc68/setup.py'"'"'; __file__='"'"'/tmp/pip-install-_dk0cwo0/psutil_968214155e33476e887f69a214c0bc68/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-4iuwbcv2/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/user/.local/include/python3.8/psutil Check the logs for full command output.

Activity

  1. added
    linux
    on Dec 15, 2020
  2. giampaolo commented on Dec 19, 2020

    @giampaolo
    Owner

    See install instructions (+ now we have wheels).

  3. kaczmarj commented on Dec 25, 2020

    @kaczmarj

    @aaronsdevera - python headers can be installed with apt install python3-dev. Typically, packages that end in -dev include headers.

  4. whomobile commented on Apr 18, 2024

    @whomobile

    In case any comes here to fix "#include <Python.h>" not found issue with psutils
    you will need to install correct python dev lib for your python.
    e.g. one of following

    apt-get install -y python3.11-dev
    apt-get install -y python3.10-dev
    apt-get install -y python3.12-dev
    apt-get install -y python3.13-dev
    
  5. added
    build-fail
    on Aug 4, 2026
  6. Repository owner locked and limited conversation to collaborators on Nov 12, 2026
  7. converted this issue into a discussion #3211 on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbuild-faillinux

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions