[SOLVED] Trying to install django get an ERROR: Could not build wheels for backports.zoneinfo, which is required to install pyproject.toml-based projects


This Content is from Stack Overflow. Question asked by Oleh

I am tryinig to install django but getting this error. Found a lot of comments how to solve this problem but nothing helped me. Maybe somebody encountered with the same issue. Python version used 3.8.9


Collecting django
  Using cached Django-4.1-py3-none-any.whl (8.1 MB)
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 sqlparse>=0.2.2
  Using cached sqlparse-0.4.2-py3-none-any.whl (42 kB)
Collecting asgiref<4,>=3.5.2
  Using cached asgiref-3.5.2-py3-none-any.whl (22 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
  ╰─> [25 lines of output]
      running bdist_wheel
      running build
      running build_py
      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/pg/zc3mbnwx42s7nk1ndm_fv5tw0000gn/T/pip-build-env-0fk0y7e4/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'
      running build_ext
      building 'backports.zoneinfo._czoneinfo' extension
      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 project


I was having the same error while deploying my application on heroku and well the problem is actually that when you are deploying it on heroku so heroku by default uses python version 3.10.x and backports.zoneinfo is not working properly with this version so I suggest you to switch to version 3.8.x(stable).

In order to do that you need to tell heroku to switch that version and it can be done as follows :

  1. Create runtime.txt in root directory.
  2. python-3.8.10 <- write this in ‘runtime.txt‘ there as to specify the version.
  3. heroku will then install this version and you will be not getting anymore error.

PS : worked it for me and later when heroku removes this bug you can switch to python latest version.

Answered by 20BCS055_Ankur Mishra, This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?