PyInstaller 与 Python:3.10.0b4 - ImportError:没有名为 _bootlocale 的模块
Posted
技术标签:
【中文标题】PyInstaller 与 Python:3.10.0b4 - ImportError:没有名为 _bootlocale 的模块【英文标题】:PyInstaller with Python: 3.10.0b4 - ImportError: No module named _bootlocale 【发布时间】:2021-09-28 05:09:12 【问题描述】:我安装了 Python 10 的 Beta 4(我必须使用它,因为我需要仅在 v3.10 中提供的模式匹配功能):
C:\Users\myname\Documents\Projects\Project Migration\SeleniumExamplePy>py -3 --version
Python 3.10.0b4
我确保我的 pyinstaller 是最新的:
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)
我在尝试将经过全面测试的 Python 代码转换为可执行文件时遇到 ImportError: No module named _bootlocale 错误:
**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
我看了这条评论 https://bugzilla.redhat.com/show_bug.cgi?id=1899950 AzyCrw4282 发布链接以回应一个非常相似的问题PyInstaller - ImportError: No module named _bootlocale Victor Stinner 2021-01-19 10:25:32 UTC
发表声明“哦,_bootlocale 是一个私有模块,不应该被导入 直接地。我删除它并用新的替换它 Python 3.10 中的 _locale._get_locale_encoding() 函数"
那么,如果模块被删除了,为什么最新的 pyinstaller 仍然试图将其拉入? 是因为我使用的是 Python 3.10b4 并且 pyinstaller 还没有更新吗? 有没有办法从可执行文件构建中排除 _bootlocale 模块以便能够构建可执行文件?
我对我的程序进行了详尽的测试,从 .py 运行时它没有问题。我不会调用任何直接引用 bootlocale 模块的东西,也不是 100% 确定它在从 3.10 中删除之前做了什么。
【问题讨论】:
请注意,作者可能已经在here解决了他的问题。 它的问题只在python中看到v3.10
我安装了v3.7.6
并且问题消失了。
【参考方案1】:
这是一个 python 3.10 兼容性问题,它被提到: https://github.com/pyinstaller/pyinstaller/issues/5693
在命令行中添加--exclude-module _bootlocale
解决了我的问题。
【讨论】:
【参考方案2】:遇到同样的问题,你只需要安装pyinstaller,然后安装3.10支持。
用途:
pip install pyinstaller
pip install https://github.com/rokm/pyinstaller/archive/refs/heads/python-3.10.zip
【讨论】:
一切正常 我收到ERROR: HTTP error 404 while getting https://github.com/rokm/pyinstaller/archive/refs/heads/python-3.10.zip
以上是关于PyInstaller 与 Python:3.10.0b4 - ImportError:没有名为 _bootlocale 的模块的主要内容,如果未能解决你的问题,请参考以下文章
Python Pyinstaller MSYS 问题与 PyQtWebKit
Python - 使用Pyinstaller将Python代码生成可执行文件
Python PyInstaller安装和使用教程(详解版)
pyinstaller 模块-python文件生成exe可执行文件