Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyinstaller";无法导入站点模块";_Python_Python 3.x_Pyinstaller - Fatal编程技术网

Python Pyinstaller";无法导入站点模块";

Python Pyinstaller";无法导入站点模块";,python,python-3.x,pyinstaller,Python,Python 3.x,Pyinstaller,我已经尝试使用PyInstaller一段时间了,因为它可以将Python脚本转换为单个.exe文件,而不是像cx\u freeze这样的库文件和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

我已经尝试使用PyInstaller一段时间了,因为它可以将Python脚本转换为单个
.exe
文件,而不是像
cx\u freeze
这样的库文件和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.
76信息:PyInstaller:4.3
76信息:Python:3.9.5
87信息:平台:Windows-10-10.0.19042-SP0
88信息:编写了C:\Users\Admin\Desktop\UnknownAIO\CLI.spec
91信息:UPX不可用。
92信息:使用路径扩展PYTHONPATH
['C:\\Users\\Admin\\Desktop\\UnknownAIO',
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\Lib\\site packages\\site.py',
'C:\\Users\\Admin\\Desktop\\UnknownAIO']
104信息:检查分析
104信息:建筑分析,因为Analysis-00.toc不存在
104信息:正在初始化模块依赖关系图。。。
108信息:缓存模块图形挂钩。。。
115警告:为模块“win32ctypes.core”定义了多个挂钩。请注意,它们不冲突。
119信息:正在分析base_library.zip。。。
致命的Python错误:初始化导入站点:导入站点模块失败
Python运行时状态:已初始化
回溯(最近一次呼叫最后一次):
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第617行,在
main()
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第604行,在main中
已知路径=addsitepackages(已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第387行,位于addsitepackages中
addsitedir(sitedir,已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第226行,位于addsitedir中
addpackage(站点目录、名称、已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第175行,在addpackage中
f=io.TextIOWrapper(io.open_代码(全名),encoding=“locale”)
LookupError:未知编码:区域设置
致命的Python错误:初始化导入站点:导入站点模块失败
Python运行时状态:已初始化
回溯(最近一次呼叫最后一次):
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第617行,在
main()
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第604行,在main中
已知路径=addsitepackages(已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第387行,位于addsitepackages中
addsitedir(sitedir,已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第226行,位于addsitedir中
addpackage(站点目录、名称、已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第175行,在addpackage中
f=io.TextIOWrapper(io.open_代码(全名),encoding=“locale”)
LookupError:未知编码:区域设置
2115信息:从“C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site packages\\PyInstaller\\hooks\\pre\u find\u module\u path\\hook distutils.py”处理预查找模块路径钩子distutils。
2116信息:distutils:重定目标到非venv目录'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib'
4439信息:缓存模块依赖关系图。。。
4528信息:运行分析-00.toc
4542信息:将Microsoft.Windows.Common-Controls添加到最终可执行文件的相关程序集
c:\users\admin\appdata\local\programs\python\python39\python.exe所需
4604警告:找不到库:c:\users\admin\appdata\local\programs\python\python39\python39.dll的api-ms-win-core-path-l1-1-0.dll依赖项
4614信息:分析C:\Users\Admin\Desktop\UnknownAIO\CLI.py
5032信息:从“C:\\Users\\Admin\\AppData\\Local\\Programs\\Python39\\lib\\site packages\\PyInstaller\\hooks\\pre\u find\u module\u path\\hook site.py”处理预查找模块路径钩子站点。
5033信息:站点:重新定位到假目录'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site packages\\PyInstaller\\fake Module'
8190信息:从“C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site packages\\PyInstaller\\hooks\\pre\u safe\u import\u module\\hook-urllib3.packages.six.py”处理预安全导入模块钩子urllib3.moves。
致命的Python错误:初始化导入站点:导入站点模块失败
Python运行时状态:已初始化
回溯(最近一次呼叫最后一次):
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第617行,在
main()
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第604行,在main中
已知路径=addsitepackages(已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第387行,位于addsitepackages中
addsitedir(sitedir,已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site packages\site.py”,第226行,位于addsitedir中
addpackage(站点目录、名称、已知路径)
文件“C:\Users\Admin\AppData\Local\Programs\Python39\lib\site packages\site.py”,第175行,在addpackage中
f=io.TextIOWrapper(io.open_代码(全名),encoding=“locale”)
LookupError:未知编码:区域设置
预安全导入模块挂钩失败,需要修复。

任何帮助都将是惊人的。

您的Python安装有问题。通常可以在Python安装目录下的
Lib
文件夹中找到。但是根据您的错误日志,PyInstaller在
Lib/site包中找到它

另见2014年:

如果在
站点包中有
site.py
,那么这是一个错误,那里不应该有这样的文件

它指的是Python2.7,但很好地解释了
site.py
的功能,并且仍然适用于新的应用程序
f = io.TextIOWrapper(io.open_code(fullname), encoding="locale")