Module ‘Typing’ not found when compiling Python 3.12 from source

  Kiến thức lập trình

On a Raspberry Pi 4, I am trying to update Python from 3.7.3 to 3.12 in order to use async for the bleak library. I understand that the only way to do this on an RPi is to compile Python from source. I followed the steps that led to a successful install. However, when I tried to install a package using pip, I got the following: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

I discovered that I need to recompile Python 3.12 with ssl enabled. Looking through the Modules/Setup file, I found this:

# NOTE: Avoid editing this file directly. Local changes should go into
# Modules/Setup.local file. To enable all modules for testing, run
#
#    sed -n -E 's/^#([a-z_*].*)$/1/p' Modules/Setup > Modules/Setup.local

So I ran the sed command. Then I ran ./configure. Then I ran make. However, I get an error:

./_bootstrap_python ./Tools/build/deepfreeze.py 
Python/frozen_modules/importlib._bootstrap.h:importlib._bootstrap 
Python/frozen_modules/importlib._bootstrap_external.h:importlib._bootstrap_external 
Python/frozen_modules/zipimport.h:zipimport 
Python/frozen_modules/abc.h:abc 
Python/frozen_modules/codecs.h:codecs 
Python/frozen_modules/io.h:io 
Python/frozen_modules/_collections_abc.h:_collections_abc 
Python/frozen_modules/_sitebuiltins.h:_sitebuiltins 
Python/frozen_modules/genericpath.h:genericpath 
Python/frozen_modules/ntpath.h:ntpath 
Python/frozen_modules/posixpath.h:posixpath 
Python/frozen_modules/os.h:os 
Python/frozen_modules/site.h:site 
Python/frozen_modules/stat.h:stat 
Python/frozen_modules/importlib.util.h:importlib.util 
Python/frozen_modules/importlib.machinery.h:importlib.machinery 
Python/frozen_modules/runpy.h:runpy 
Python/frozen_modules/__hello__.h:__hello__ 
Python/frozen_modules/__phello__.h:__phello__ 
Python/frozen_modules/__phello__.ham.h:__phello__.ham 
Python/frozen_modules/__phello__.ham.eggs.h:__phello__.ham.eggs 
Python/frozen_modules/__phello__.spam.h:__phello__.spam 
Python/frozen_modules/frozen_only.h:frozen_only 
-o Python/deepfreeze/deepfreeze.c
Traceback (most recent call last):
  File "/home/pi/lib/python3.12.2/Python-3.12.2/./Tools/build/deepfreeze.py", line 17, in <module>
    from typing import Dict, FrozenSet, TextIO, Tuple
  File "/home/pi/lib/python3.12.2/Python-3.12.2/Lib/typing.py", line 36, in <module>
    from _typing import (
ModuleNotFoundError: No module named '_typing'
make: *** [Makefile:1407: Python/deepfreeze/deepfreeze.c] Error 1

It appears that I am missing the module Typing. How do I install the module Typing without using pip? Is this a Catch-22 situation?

How do I get around this error?

LEAVE A COMMENT