Pyinstaller“无法导入站点模块”

b24l

我一直在尝试使用 PyInstaller,因为它可以将 Python 脚本转换为单个.exe文件,而不是像cx_freeze例如那样拥有 lib 文件和 DLL 因此,当我推送时,我的用户可以更轻松地更新程序,因为要下载的内容“更少”。

但是,当我运行“pyinstaller CLI.py”时,出现以下错误:

76 INFO: PyInstaller: 4.3
76 INFO: Python: 3.9.5
87 INFO: Platform: Windows-10-10.0.19042-SP0
88 INFO: wrote C:\Users\Admin\Desktop\UnknownAIO\CLI.spec
91 INFO: UPX is not available.
92 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Admin\\Desktop\\UnknownAIO',
 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\Lib\\site-packages\\site.py',
 'C:\\Users\\Admin\\Desktop\\UnknownAIO']
104 INFO: checking Analysis
104 INFO: Building Analysis because Analysis-00.toc is non existent
104 INFO: Initializing module dependency graph...
108 INFO: Caching module graph hooks...
115 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
119 INFO: Analyzing base_library.zip ...
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 617, in <module>
    main()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 604, in main
    known_paths = addsitepackages(known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 387, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 226, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 175, in addpackage
    f = io.TextIOWrapper(io.open_code(fullname), encoding="locale")
LookupError: unknown encoding: locale
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 617, in <module>
    main()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 604, in main
    known_paths = addsitepackages(known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 387, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 226, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 175, in addpackage
    f = io.TextIOWrapper(io.open_code(fullname), encoding="locale")
LookupError: unknown encoding: locale
2115 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
2116 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib'
4439 INFO: Caching module dependency graph...
4528 INFO: running Analysis Analysis-00.toc
4542 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\admin\appdata\local\programs\python\python39\python.exe
4604 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of c:\users\admin\appdata\local\programs\python\python39\python39.dll
4614 INFO: Analyzing C:\Users\Admin\Desktop\UnknownAIO\CLI.py
5032 INFO: Processing pre-find module path hook site from 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
5033 INFO: site: retargeting to fake-dir 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\fake-modules'
8190 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 617, in <module>
    main()
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 604, in main
    known_paths = addsitepackages(known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 387, in addsitepackages
    addsitedir(sitedir, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 226, in addsitedir
    addpackage(sitedir, name, known_paths)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\site.py", line 175, in addpackage
    f = io.TextIOWrapper(io.open_code(fullname), encoding="locale")
LookupError: unknown encoding: locale
pre-safe-import-module hook failed, needs fixing.

任何帮助将是惊人的。

约翰·亨尼格

您的 Python 安装有问题。“网站特定的配置挂钩”site.py是在通常发现的Lib文件夹正下方Python的安装目录。但是根据您的错误日志,PyInstaller 在Lib/site-packages.

另请参阅2014 年的此答案

如果你有一个site.pyinsite-packages那么这是一个错误,那里应该没有这样的文件。

它指的是 Python 2.7,但很好地解释了哪些内容site.py适用于较新的 Python 版本,例如此处的 Python 3.9。

此外,代码行

f = io.TextIOWrapper(io.open_code(fullname), encoding="locale")

在你的习惯site.py是错误的。没有(标准)编码的名称'locale'这就是它提出这一点的原因LookupError代码在同一行site.py包括在Python 3.9不使用可选的encoding参数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章