stlite: ModuleNotFoundError: The module 'micropip' is included in the Pyodide distribution, but it is not installed.

I get this error trace while I was trying to build my streamlit project from inside of project package

PythonError: Traceback (most recent call last):
  File "/lib/python311.zip/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1209, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1181, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1145, in _find_and_load_unlocked
ModuleNotFoundError: The module 'micropip' is included in the Pyodide distribution, but it is not installed.
You can install it by calling:
  await micropip.install("micropip") in Python, or
  await pyodide.loadPackage("micropip") in JavaScript
See https://pyodide.org/en/stable/usage/loading-packages.html for more details.

    at new_error (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:14992)
    at wasm://wasm/02237e6e:wasm-function[291]:0x152d67
    at wasm://wasm/02237e6e:wasm-function[292]:0x152e6c
    at Module._pythonexc2js (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:654797)
    at Module.callPyObjectKwargs (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:75609)
    at Module.callPyObject (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:75818)
    at PyProxy.apply (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:89069)
    at Object.apply (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:87847)
    at Object.pyimport (/Users/***/***/root/node_modules/pyodide/pyodide.asm.js:9:123442)
    at E (/Users/***/***/root/node_modules/@stlite/desktop/bin/dump_artifacts.js:3:3102)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /Users/***/***/root/node_modules/@stlite/desktop/bin/dump_artifacts.js:14:2351 {
  type: 'ModuleNotFoundError',
  __error_address: 9705648

The project structure was something like this:

  • root
    • directory_a
      • my_st_code.py
    • package.json
    • requirements.txt

I tried both npm run dump directory_a and npm run dump directory_a -- -r requirements.txt but I took same error on both of them

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

This error occurs when you are on a restricted network for instance, on corporate network. This means that cdn.delivry.js is blocked on the network which is preventing the download of micropip and other whl files. To get around it, manually download the pyodide latest release from here (https://github.com/pyodide/pyodide/releases/tag/0.25.0) and extract it in the pyodide folder of node_modules.

This would get rid of the error but it might create a new one because we are still on restricted network and there are a lot of dependencies being accessed from various different urls.

To know what is actually getting restricted, use stlite mountable and inspect network in browser. This just tells where the issue lies, doesn’t fix it. The only way to fix it to get it unblocked or switching to a unrestricted network. I tried hosting the whl pyodide and stlite files for stlite-mountable on localhost which worked and loaded micropip but then it got blocked at tenacity-8.2.3-py3-none-any.whl and six other whl required from https://files.pythonhosted.org. I am not sure how to redirect those requests to my local server.