Skip to content

pip fails with No module named 'encodings' in pyodide venv created from uv python #143

Description

@oscarbenjamin

This is coming from https://discuss.python.org/t/pep-776-emscripten-support/84996/20

I see an error when following the instructions from the docs to create venv and use pip:
https://pyodide.org/en/stable/development/building-and-testing-packages.html

It is possible that this is due to using a uv installed Python.

Specifically I run these commands that seem to complete successfully until the last:

uv python install 3.12
uv venv -p 3.12 .venv
source .venv/bin/activate
uv pip install pip
pip install pyodide-build
pyodide venv .venv_pyodide
source .venv_pyodide/bin/activate
pip # error

The error I see is (I have redacted two paths):

$ pip
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = '.../.venv_pyodide/bin/python3.12-host'
  isolated = 0
  environment = 1
  user site = 0
  safe_path = 0
  import site = 1
  is in build tree = 0
  stdlib dir = '/install/lib/python3.12'
  sys._base_executable = '/home/oscar/.local/share/uv/python/cpython-3.12.9-linux-x86_64-gnu/bin/python3.12'
  sys.base_prefix = '/install'
  sys.base_exec_prefix = '/install'
  sys.platlibdir = 'lib'
  sys.executable = '.../.venv_pyodide/bin/python3.12-host'
  sys.prefix = '/install'
  sys.exec_prefix = '/install'
  sys.path = [
    '/install/lib/python312.zip',
    '/install/lib/python3.12',
    '/install/lib/python3.12/lib-dynload',
  ]
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 0x00007b7352aeb740 (most recent call first):
  <no Python frame>

I have not tested this yet with a non-uv Python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions