Fatal error: Python.h: No such file or directory

I’m wondering how to manage my python 3.8 environment in github actions, I’m using the following in my action, but I can’t seem to get the headers into the PATH.

fatal error: Python.h: No such file or directory

332 124 | #include <Python.h>

333

  # Sets up python3
  - uses: actions/setup-python@v2
    with:
      python-version: 3.8 

  # Installs and upgrades pip, installs other dependencies and installs the package from setup.py
  - name: "Installs and upgrades pip, installs other dependencies and installs the package from setup.py"
    run: |
      # dev headers
      sudo apt-get install python3.8-dev  # for python3.x installs
      sudo apt-get install libpython3.8-dev
      # Upgrade pip
      python3 -m pip install --upgrade pip
      # Install build deps
      python3 -m pip install setuptools wheel twine
      # If requirements.txt exists, install from it
      if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      # Install the package from setup.py
      python3 setup.py install

It looks like you’re mixing the Python version set up by actions/setup-python with one from the Ubuntu repositories. python3 should be the version from Ubuntu (actions/setup-python defines what python is), but this line uses pip, not the pip module available to python3:

I don’t know which version is better for your project, but mixing probably isn’t good. I’m not sure if actions/setup-python provides the C headers, if not you might have to use the Ubuntu version.

1 Like

It turns out I had a non portable path set up in my cmakelists.txt that setup.py was running. To confirm for future travelers, just using actions/setup-python@v2 should have the C headers installed in /usr/include/python3.8 (in this case) should work as expected, the ubuntu headers aren’t required, so I deleted them.

1 Like