首页 > 解决方案 > 致命的 Python 错误:init_fs_encoding: failed to get the Python codec of the filesystem encoding Mac

问题描述

python 3.9.7我已经使用版本在 MacOS BigSur 11.6 上设置了一个虚拟环境。环境名称是“ambiente”,这就是终端的样子:

(ambiente) mac.fede@Ahoga PageDownloader % 

我在PageDownloader目录中。在这个文件夹里面有我的 python 项目。我可以使用 : 运行程序python3 PageDownloader.py,一切正常。

我尝试使用它来安装和运行它PyInstaller,并且 UNIX 可执行文件工作正常。

然后使用Platypus我将它装瓶到一个应用程序中,当双击该图标时,一个 shell 脚本运行并启动之前获得的 UNIX 可执行文件。

当我双击应用程序时,这是输出:

​initializing script //this launches PageDownloader Executable file

Python path configuration:
  PYTHONHOME = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources'
  PYTHONPATH = (not set)
  program name = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
  isolated = 0
  environment = 0
  user site = 0
  import site = 0
  sys._base_executable = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
  sys.base_prefix = ''
  sys.base_exec_prefix = ''
  sys.platlibdir = 'lib'
  sys.executable = '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/PageDownloader'
  sys.prefix = ''
  sys.exec_prefix = ''
  sys.path = [
    '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/base_library.zip',
    '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources/lib-dynload',
    '/Users/mac.fede/Documents/GitHub/PageDownloader/PageDownloader.app/Contents/Resources',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x000000010c0cfe00 (most recent call first):
<no Python frame>

StackOverflow 上的其他帖子如下:Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding, when trying to start uwsgi

建议删除PYTHONHOME环境变量,但我不知道该怎么做。我可以看到它已经设置并且不应该。我在互联网上做了一些研究,但我不明白如何在 Mac 上做到这一点。我已经尝试过:

unset PYTHONPATH
unset PYTHONHOME

在启动可执行文件但同样的错误之前。现在,我不知道这是否是在 MacOS 上从 python 程序创建可导出应用程序的正确方法,我正试图弄清楚,所以所有这些解决方案都是“自制的”。如果您有任何建议,我将很高兴听到。

“可导出”是指我可以与我的朋友或其他人共享并且可以通过双击运行的应用程序。

标签: pythonmacos

解决方案


推荐阅读