APScheduler cannot be installed due to lib/zoneinfo_module.c:1:10: fatal error: 'Python.h' file not found on MacOS

Question:

I want to install APScheduler in a python project but I have some issues.
I tried before to install wheel but I got the same kind of errors. Even if I installed Xcode, nothing is changed

pip install APScheduler

Collecting APScheduler
  Using cached APScheduler-3.9.1-py2.py3-none-any.whl (59 kB)
Requirement already satisfied: setuptools>=0.7 in ./venv/lib/python3.8/site-packages (from APScheduler) (65.3.0)
Requirement already satisfied: pytz in ./venv/lib/python3.8/site-packages (from APScheduler) (2022.2.1)
Collecting tzlocal!=3.*,>=2.0
  Using cached tzlocal-4.2-py3-none-any.whl (19 kB)
Requirement already satisfied: six>=1.4.0 in ./venv/lib/python3.8/site-packages (from APScheduler) (1.16.0)
Collecting pytz-deprecation-shim
  Using cached pytz_deprecation_shim-0.1.0.post0-py2.py3-none-any.whl (15 kB)
Collecting backports.zoneinfo
  Using cached backports.zoneinfo-0.2.1.tar.gz (74 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting tzdata
  Using cached tzdata-2022.2-py2.py3-none-any.whl (336 kB)
Building wheels for collected packages: backports.zoneinfo
  Building wheel for backports.zoneinfo (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for backports.zoneinfo (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [41 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.14-arm64-cpython-38
      creating build/lib.macosx-10.14-arm64-cpython-38/backports
      copying src/backports/__init__.py -> build/lib.macosx-10.14-arm64-cpython-38/backports
      creating build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/_version.py -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/_common.py -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/__init__.py -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/_zoneinfo.py -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/_tzpath.py -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      running egg_info
      writing src/backports.zoneinfo.egg-info/PKG-INFO
      writing dependency_links to src/backports.zoneinfo.egg-info/dependency_links.txt
      writing requirements to src/backports.zoneinfo.egg-info/requires.txt
      writing top-level names to src/backports.zoneinfo.egg-info/top_level.txt
      reading manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      /private/var/folders/q_/k3t2_n9n0ggfjs369gz92f800000gn/T/pip-build-env-0272_x8x/overlay/lib/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
        warnings.warn(msg, warning_class)
      warning: no files found matching '*.png' under directory 'docs'
      warning: no files found matching '*.svg' under directory 'docs'
      no previously-included directories found matching 'docs/_build'
      no previously-included directories found matching 'docs/_output'
      adding license file 'LICENSE'
      adding license file 'licenses/LICENSE_APACHE'
      writing manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
      copying src/backports/zoneinfo/__init__.pyi -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      copying src/backports/zoneinfo/py.typed -> build/lib.macosx-10.14-arm64-cpython-38/backports/zoneinfo
      running build_ext
      building 'backports.zoneinfo._czoneinfo' extension
      creating build/temp.macosx-10.14-arm64-cpython-38
      creating build/temp.macosx-10.14-arm64-cpython-38/lib
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/Users/dpv/PycharmProjects/ctd-websockets/venv/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -c lib/zoneinfo_module.c -o build/temp.macosx-10.14-arm64-cpython-38/lib/zoneinfo_module.o -std=c99
      lib/zoneinfo_module.c:1:10: fatal error: 'Python.h' file not found
      #include "Python.h"
               ^~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' 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 backports.zoneinfo
Failed to build backports.zoneinfo
ERROR: Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects

I have seen similar project, but I could not fix it with the solution seen already.

My setup:

  • Python 3.8
  • macOS Monterey (12.6)
  • Apple Silicon
  • Xcode 14.0
Asked By: dpv

||

Answers:

The build is looking for /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers, but if you don’t have full Xcode installed, this won’t exist.

You can work around this problem by overriding the environment variable C_INCLUDE_PATH:

…with the system Python 3 headers:

export C_INCLUDE_PATH=/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/Headers
pip install backports.zoneinfo

…or, better yet, your specific Homebrew-installed Python headers:

export C_INCLUDE_PATH=/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/Headers
pip install backports.zoneinfo
Answered By: jrc
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.