PyOxidizer icon indicating copy to clipboard operation
PyOxidizer copied to clipboard

init_fs_encoding fails when include_distribution_sources = False

Open 9001 opened this issue 3 years ago • 2 comments

Hey :-) When I set include_distribution_sources = False, the interpreter fails to start:

$ pyoxidizer run --release --target-triple i686-pc-windows-msvc
[ ... ]
Python path configuration:
  PYTHONHOME = 'C:\w\build\i686-pc-windows-msvc\release\install\foo'
  PYTHONPATH = (not set)
  program name = 'C:\w\build\i686-pc-windows-msvc\release\install\foo\foo.exe'
  isolated = 1
  environment = 0
  user site = 0
  import site = 1
  sys._base_executable = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo\\foo.exe'
  sys.base_prefix = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo'
  sys.base_exec_prefix = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo\\foo.exe'
  sys.prefix = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo'
  sys.exec_prefix = 'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo'
  sys.path = [
    'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo\\python310.zip',
    'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo\\DLLs',
    'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo\\lib',
    'C:\\w\\build\\i686-pc-windows-msvc\\release\\install\\foo',
  ]
error instantiating embedded Python interpreter: during initializing Python main: init_fs_encoding: failed to get the Python codec of the filesystem encoding
error: cargo run failed

my pyoxidizer.bzl is:

def make_exe():
    dist = default_python_distribution()
    policy = dist.make_python_packaging_policy()
    policy.include_distribution_sources = False
    python_config = dist.make_python_interpreter_config()
    exe = dist.to_python_executable(
        name="foo",
        config=python_config,
        packaging_policy=policy,
    )
    return exe

def make_embedded_resources(exe):
    return exe.to_embedded_resources()

def make_install(exe):
    files = FileManifest()
    files.add_python_resource("foo", exe)
    return files

register_target("exe", make_exe)
register_target("resources", make_embedded_resources, depends=["exe"], default_build_script=True)
register_target("install", make_install, depends=["exe"], default=True)
resolve_targets()

At first I thought it was due to some other specifics of my bzl (static build, py3.8 for win7 support, windows_runtime_dlls_mode=never) but it still happens after simplifying it to this.

My assumption was that it would compile the source modules to bytecode and include those into the exe instead; maybe I'm mistaken? Seeing the PYTHONHOME in the output, is the intention to provide your own copy of the stdlib, similar to the zipfile in the official cpython windows-embedded-packages?

9001 avatar Sep 10 '22 17:09 9001

I have this problem as well, on Windows 10, using python 3.10, using both flavor="standalone-static" and flavor="standalone-dynamic".

kambe-mikb avatar Nov 11 '22 07:11 kambe-mikb

This is a duplicate of #312

wkschwartz avatar Dec 12 '22 19:12 wkschwartz