10

I have Beta 4 of Python 10 installed (which I must use because I need pattern matching feature only available in v3.10):

C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy>py -3 --version
Python 3.10.0b4

and I made sure my pyinstaller is up to date:

    C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy>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>=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>=2020.6 in c:\users\myname\appdata\local\programs\python\python310\lib\site-packages (from pyinstaller) (2021.2)
Requirement already satisfied: pywin32-ctypes>=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>=2017.8.1->pyinstaller) (0.18.2)

I am getting ImportError: No module named _bootlocale error while trying to convert my python code that I thoroughly tested to executable:

**C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy>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 "c:\users\myname\appdata\local\programs\python\python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\myname\appdata\local\programs\python\python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\myname\AppData\Local\Programs\Python\Python310\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\__main__.py", line 126, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py", line 758, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py", line 705, in build
    exec(code, spec_namespace)
  File "ExtractRules.spec", line 7, in <module>
    a = Analysis(['ExtractRules.py'],
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py", line 254, in __init__
    self.__postinit__()
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\datastruct.py", line 159, in __postinit__
    self.assemble()
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\building\build_main.py", line 354, in assemble
    self.graph = initialize_modgraph(
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py", line 882, in initialize_modgraph
    graph = PyiModuleGraph(
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py", line 122, in __init__
    self._analyze_base_modules()
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py", line 289, in _analyze_base_modules
    self._base_modules = [mod
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\depend\analysis.py", line 291, in <listcomp>
    for mod in self.import_hook(req)]
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook
    target_package, target_module_partname = self._find_head_package(
  File "c:\users\myname\appdata\local\programs\python\python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1711, in _find_head_package
    raise ImportError("No module named " + target_package_name)
ImportError: No module named _bootlocale

I looked at this comment https://bugzilla.redhat.com/show_bug.cgi?id=1899950 that AzyCrw4282 posted the link to in response to a very similar question PyInstaller - ImportError: No module named _bootlocale and there is a statement by Victor Stinner 2021-01-19 10:25:32 UTC

"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"

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?

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.

Yun
  • 3,056
  • 6
  • 9
  • 28
SLB
  • 101
  • 1
  • 1
  • 4

7 Answers7

21

It's a Python 3.10 compatibility issue, and it's mentioned here.

You can solve it by adding --exclude-module _bootlocale to your command.

For instance:

pyinstaller.exe app.py --exclude-module _bootlocale
galoget
  • 722
  • 9
  • 15
LingYan Meng
  • 699
  • 4
  • 12
12

Had the same problem, all you need is to install pyinstaller and then install the 3.10 support.

Use:

pip install pyinstaller
pip install https://github.com/rokm/pyinstaller/archive/refs/heads/python-3.10.zip
Stav Gafny
  • 121
  • 1
  • 4
5

Try to install the latest version of Pyinstaller
This solves me the problem:

pip install pyinstaller==4.10
MeBex
  • 488
  • 1
  • 5
  • 20
3

This appears to be a version mismatch between pyinstaller and python. I recently upgraded to python3.10, installed from requirements.txt, and then had this issue. I was running pyinstaller 4.5.1, but the latest is pyinstaller 5.1. You can get the latest pyinstaller by doing the following:

pip install --upgrade pyinstaller

or

python -m pip install --upgrade pyinstaller
galoget
  • 722
  • 9
  • 15
BenMcLean981
  • 700
  • 5
  • 16
  • 1
    As of August 2022 this appears to be the currently most useful answer. Others have more upvotes but they are also old, and the `pyinstaller` version is relevant. – BoarGules Aug 12 '22 at 20:38
1

Use this command to install pyinstaller first.

pip install pyinstaller==4.10

Or if you want to install the latest version of pyinstaller use:

pip install pyinstaller

After installing try to create your exe again and it will work.

galoget
  • 722
  • 9
  • 15
1

in my case i solved it by uninstalling the fbs package

pip3 uninstall fbs
ariandi
  • 11
  • 3
1

I fixed it in my poetry project by editing pyproject.toml:

[tool.poetry.dependencies]
python = "^3.8"

to

[tool.poetry.dependencies]
python = "^3.8,<3.11"
Pux
  • 421
  • 3
  • 18