'PyInstaller with Python: 3.10.0b4 - ImportError: No module named _bootlocale
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.
Solution 1:[1]
It's a python 3.10 compatibility issue, and it's mentioned: https://github.com/pyinstaller/pyinstaller/issues/5693
And adding --exclude-module _bootlocale
to the command line solved my issue.
Solution 2:[2]
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
Solution 3:[3]
Try to install the latest version of Pyinstaller
This solves me the problem:
pip install pyinstaller==4.10
Solution 4:[4]
use this command to install pyinstaller first.pip install pyinstaller==4.10
or installer the latest version of pyinstaller insteed of 4.10.
after installing try to make exe.
i hope this works
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Stav Gafny |
Solution 3 | MeBex |
Solution 4 | Tanu Patel |