title: PyInstaller with Python: 3.10.0b4 - ImportError: No module named _bootlocale
body: <p>I have Beta 4 of Python 10 installed (which I must use because I need pattern matching feature only available in v3.10):</p>
  <pre><code>C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy&gt;py -3 --version
  Python 3.10.0b4
  </code></pre>
  <p>and I made sure my pyinstaller is up to date:</p>
  <pre><code>    C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy&gt;pip install --upgrade pyinstaller
  Requirement already satisfied: pyinstaller in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (4.4)
  Requirement already satisfied: pefile&gt;=2017.8.1 in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (2021.5.24)
  Requirement already satisfied: pyinstaller-hooks-contrib&gt;=2020.6 in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (2021.2)
  Requirement already satisfied: pywin32-ctypes&gt;=0.2.0 in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (0.2.0)
  Requirement already satisfied: setuptools in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (56.0.0)
  Requirement already satisfied: altgraph in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (0.17)
  Requirement already satisfied: future in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pefile&gt;=2017.8.1-&gt;pyinstaller) (0.18.2)
  </code></pre>
  <p>I am getting <strong>ImportError: No module named _bootlocale</strong> error while trying to convert my python code that I thoroughly tested to executable:</p>
  <pre><code>**C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy&gt;pyinstaller --onefile --clean ExtractRules.spec**
  83 INFO: PyInstaller: 4.4
  83 INFO: Python: 3.10.0b4
  100 INFO: Platform: Windows-10-10.0.18363-SP0
  110 INFO: UPX is not available.
  110 INFO: Removing temporary files and cleaning cache in C:\Users\myname\AppData\Local\pyinstaller
  113 INFO: Extending PYTHONPATH with paths
  ['C:\\Users\\myname\\Documents\\Projects\\Project '
   'Migration\\SeleniumExamplePy',
   'C:\\Users\\myname\\Documents\\Projects\\Project '
   'Migration\\SeleniumExamplePy']
  126 INFO: checking Analysis
  126 INFO: Building Analysis because Analysis-00.toc is non existent
  126 INFO: Initializing module dependency graph...
  126 INFO: Caching module graph hooks...
  139 INFO: Analyzing base_library.zip ...
  3449 INFO: Processing pre-find module path hook distutils from 'c:\\users\\myname\\appdata\\local\\programs\\python\\python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
  3449 INFO: distutils: retargeting to non-venv dir 'c:\\users\\myname\\appdata\\local\\programs\\python\\python310\\lib'
  Traceback (most recent call last):
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\runpy.py&quot;, line 196, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\runpy.py&quot;, line 86, in _run_code
      exec(code, run_globals)
    File &quot;C:\Users\myname\AppData\Local\Programs\Python\Python310\Scripts\pyinstaller.exe\__main__.py&quot;, line 7, in &lt;module&gt;
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\__main__.py&quot;, line 126, in run
      run_build(pyi_config, spec_file, **vars(args))
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\__main__.py&quot;, line 65, in run_build
      PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py&quot;, line 758, in main
      build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py&quot;, line 705, in build
      exec(code, spec_namespace)
    File &quot;ExtractRules.spec&quot;, line 7, in &lt;module&gt;
      a = Analysis(['ExtractRules.py'],
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py&quot;, line 254, in __init__
      self.__postinit__()
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\datastruct.py&quot;, line 159, in __postinit__
      self.assemble()
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py&quot;, line 354, in assemble
      self.graph = initialize_modgraph(
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py&quot;, line 882, in initialize_modgraph
      graph = PyiModuleGraph(
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py&quot;, line 122, in __init__
      self._analyze_base_modules()
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py&quot;, line 289, in _analyze_base_modules
      self._base_modules = [mod
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py&quot;, line 291, in &lt;listcomp&gt;
      for mod in self.import_hook(req)]
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py&quot;, line 1505, in import_hook
      target_package, target_module_partname = self._find_head_package(
    File &quot;c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py&quot;, line 1711, in _find_head_package
      raise ImportError(&quot;No module named &quot; + target_package_name)
  ImportError: No module named _bootlocale
  </code></pre>
  <p>I looked at this comment
  <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1899950" rel="noreferrer">https://bugzilla.redhat.com/show_bug.cgi?id=1899950</a>
  that <a href="https://stackoverflow.com/users/6505847/azycrw4282">AzyCrw4282</a> posted the link to in response to a very similar question <a href="https://stackoverflow.com/questions/66600654/pyinstaller-importerror-no-module-named-bootlocale">PyInstaller - ImportError: No module named _bootlocale</a>
  and there is a statement by <em>Victor Stinner 2021-01-19 10:25:32 UTC</em></p>
  <blockquote>
  <p>&quot;Oh, _bootlocale was a private module which should not be imported
  directly. I removed it and replaced it with a new
  _locale._get_locale_encoding() function in Python 3.10&quot;</p>
  </blockquote>
  <p>So, if the module was removed, why the latest pyinstaller still tries to pull it in?
  Is it because I am using Python 3.10b4 and pyinstaller was not updated for it yet?
  Is there a way to exclude the _bootlocale module from the executable build to be able to build the executable?</p>
  <p>I tested my program exhaustively and it works with no problem when run from .py. I do not call anything that directly refers to bootlocale module, not 100% sure what it does or did before being removed from 3.10.</p>