简体   繁体   English

带有 Python 的 PyInstaller:3.10.0b4 - ImportError:没有名为 _bootlocale 的模块

[英]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):我安装了 Python 10 的 Beta 4(我必须使用它,因为我需要仅在 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:我确保我的 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)

I am getting ImportError: No module named _bootlocale error while trying to convert my python code that I thoroughly tested to executable:我在尝试将经过彻底测试的 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

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我查看了这条评论https://bugzilla.redhat.com/show_bug.cgi?id=1899950AzyCrw4282发布了链接以回应一个非常相似的问题PyInstaller - ImportError: No module named _bootlocale并且Victor有一个声明斯廷纳 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" “哦,_bootlocale 是一个私有模块,不应直接导入。我将其删除并用 Python 3.10 中的新 _locale._get_locale_encoding() function 替换它”

So, if the module was removed, why the latest pyinstaller still tries to pull it in?那么,如果模块被删除,为什么最新的 pyinstaller 仍然试图将其拉入? Is it because I am using Python 3.10b4 and pyinstaller was not updated for it yet?是因为我使用的是 Python 3.10b4 并且 pyinstaller 还没有更新吗? Is there a way to exclude the _bootlocale module from the executable build to be able to build the executable?有没有办法从可执行文件构建中排除 _bootlocale 模块以便能够构建可执行文件?

I tested my program exhaustively and it works with no problem when run from.py.我对我的程序进行了详尽的测试,从.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.我不会调用任何直接引用 bootlocale 模块的东西,也不是 100% 确定它在从 3.10 中删除之前做了什么或做了什么。

It's a Python 3.10 compatibility issue, and it's mentioned here .这是一个 Python 3.10 兼容性问题,这里提到了

You can solve it by adding --exclude-module _bootlocale to your command.您可以通过在命令中添加--exclude-module _bootlocale来解决它。

For instance:例如:

pyinstaller.exe app.py --exclude-module _bootlocale

Had the same problem, all you need is to install pyinstaller and then install the 3.10 support.有同样的问题,你只需要安装 pyinstaller 然后安装 3.10 支持。

Use:利用:

pip install pyinstaller
pip install https://github.com/rokm/pyinstaller/archive/refs/heads/python-3.10.zip

Try to install the latest version of Pyinstaller尝试安装最新版本的 Pyinstaller
This solves me the problem:这解决了我的问题:

pip install pyinstaller==4.10

Add --exclude-module _bootlocale to the command line Solved for me.将 --exclude-module _bootlocale 添加到命令行为我解决。 Thank you very much @LingYan Meng非常感谢@LingYan Meng

Use this command to install pyinstaller first.使用此命令首先安装pyinstaller

pip install pyinstaller==4.10

Or if you want to install the latest version of pyinstaller use:或者,如果您想安装最新版本的pyinstaller ,请使用:

pip install pyinstaller

After installing try to create your exe again and it will work.安装后尝试再次创建您的exe,它将起作用。

This appears to be a version mismatch between pyinstaller and python.这似乎是 pyinstaller 和 python 之间的版本不匹配。 I recently upgraded to python3.10, installed from requirements.txt, and then had this issue.我最近升级到 python3.10,从 requirements.txt 安装,然后遇到了这个问题。 I was running pyinstaller 4.5.1, but the latest is pyinstaller 5.1.我正在运行 pyinstaller 4.5.1,但最新的是 pyinstaller 5.1。 You can get the latest pyinstaller by doing the following:您可以通过执行以下操作获取最新的 pyinstaller:

pip install --upgrade pyinstaller

or或者

python -m pip install --upgrade pyinstaller

在我的情况下,我通过卸载 fbs 包解决了它

pip3 uninstall fbs

I fixed it in my poetry project by editing pyproject.toml:我通过编辑 pyproject.toml 在我的诗歌项目中修复了它:

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

to

[tool.poetry.dependencies]
python = "^3.8,<3.11"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PyInstaller - ImportError:没有名为 _bootlocale 的模块 - PyInstaller - ImportError: No module named _bootlocale “Pyinstaller 错误”引发 ImportError(“没有名为”的模块“+ target_package_name)ImportError:没有名为 _bootlocale 的模块 - "Pyinstaller error" raise ImportError("No module named " + target_package_name) ImportError: No module named _bootlocale 我收到错误 ImportError: No module named _bootlocale while runnig pyinstaller on linux - I get error ImportError: No module named _bootlocale while runnig pyinstaller on linux ImportError:没有名为b的模块-Python - ImportError: No module named b - Python Python 2.7.3-ImportError:没有名为PyInstaller的模块 - Python 2.7.3 - ImportError: No module named PyInstaller PyInstaller“ImportError:没有名为Pyinstaller的模块” - PyInstaller “ImportError: No module named Pyinstaller” PyInstaller:“导入错误:没有名为 htmlentitydefs 的模块” - PyInstaller: “ImportError: No module named htmlentitydefs” PyInstaller:“ImportError:没有名为 os 的模块” - PyInstaller: “ImportError: No module named os” PyInstaller ImportError:没有名为spiderloader的模块 - PyInstaller ImportError: No module named spiderloader PyInstaller-ImportError:没有名为“ rethinkdb”的模块 - PyInstaller - ImportError: No module named 'rethinkdb'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM