Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
SimplyEgeBULUT opened this issue Nov 2, 2023 · 15 comments · Fixed by #937

Comments

@SimplyEgeBULUT
Copy link

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.

@DuelistRaj
Copy link

Hi, I am encountering the same error. Were you able to fix it?

@DDidas
Copy link

DDidas commented Mar 11, 2024

Hi, I am encountering the same error. Were you able to fix it?

I encounter the same problem:

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 (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:12519)
    at wasm://wasm/02250ad6:wasm-function[295]:0x158827
    at wasm://wasm/02250ad6:wasm-function[296]:0x15892c
    at Module._pythonexc2js (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:640895)
    at Module.callPyObjectKwargs (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:81856)
    at Module.callPyObject (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:82066)
    at Function.apply (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:97147)
    at Object.apply (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:95381)
    at Object.pyimport (C:\Users\A200162672\Desktop\ars_app\node_modules\pyodide\pyodide.asm.js:9:119720)
    at j (C:\Users\A200162672\Desktop\ars_app\node_modules\@stlite\desktop\bin\dump_artifacts.js:3:2648)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async H (C:\Users\A200162672\Desktop\ars_app\node_modules\@stlite\desktop\bin\dump_artifacts.js:3:2059)
    at async C:\Users\A200162672\Desktop\ars_app\node_modules\@stlite\desktop\bin\dump_artifacts.js:17:2040 {
  type: 'ModuleNotFoundError',
  __error_address: 9780520

@whitphx
Copy link
Owner

whitphx commented Mar 14, 2024

Sorry for my late reply.
Can you share the following info?

  • Which version of @stlite/desktop are you using?
    • If it's not the latest one, please try the latest version.
  • What are the requirements you are trying to install when specifying requirements.txt?

@DDidas
Copy link

DDidas commented Mar 14, 2024

  • Which version of @stlite/desktop are you using?

The version is 0.47.0, should be the newest

  • What are the requirements you are trying to install when specifying requirements.txt?

The requirement is just pandas, the same error occurs also, when i try to run 'npm run dump streamlit_app pandas'

@whitphx
Copy link
Owner

whitphx commented Mar 14, 2024

Thank you.
Unfortunately I couldn't reproduce it in my env (Mac).

  • What if you remove node_modules and re-install the packages?
  • Can you provide the whole log shown after npm run dump?

@DDidas
Copy link

DDidas commented Mar 14, 2024

I tried deleting the folder and reinstalling several times, with different node/npm versions and with yarn. same behaviour every time. My machine runs windows, on a mac the same project dumped as expected.

The log is in the attached .txt.
log.txt

Thank you for the fast answer :)

@DuelistRaj
Copy link

DuelistRaj commented Mar 14, 2024

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.

@DuelistRaj
Copy link

DDias I see the same issue as mine in your log.txt

@DDidas
Copy link

DDidas commented Mar 14, 2024

You are right, I am in a restricted corporate network. Downloading the pyodide folder didn't fix any error for me, but at least I know the reason now.

@DuelistRaj
Copy link

You need to extract the contents of the pyodide folder, the one with pyodide.js and move all the individual files into the pyodide folder of node_modules. If pythonhosted url works for you, stlite-mountable should work.

P.S. If anyone knows how to redirect requests for tenacity, altair, etc from pythonhosted to a local server please do let me know.

@whitphx
Copy link
Owner

whitphx commented Mar 14, 2024

Thank you both, all makes sense.
Please use the workaround @DuelistRaj introduced.

I will pin the following 2 tasks for future improvements.

  1. Add an option to set the Pyodide download URL different from jsdelivr, or a local Pyodide directory.
  1. Improve the error message.
  • I found the following logs at the very top of the log.txt, while I imagine it's very hard to find on the terminal when you hit this problem as the log you see is confusing ("ModuleNotFoundError: The module 'micropip' is included in the Pyodide distribution, but it is not installed.").
Didn't find package micropip-0.5.0-py3-none-any.whl locally, attempting to load from https://cdn.jsdelivr.net/pyodide/v0.24.1/full/
Didn't find package packaging-23.1-py3-none-any.whl locally, attempting to load from https://cdn.jsdelivr.net/pyodide/v0.24.1/full/
Failed to load micropip, packaging
The following error occurred while loading micropip:
request to https://cdn.jsdelivr.net/pyodide/v0.24.1/full/micropip-0.5.0-py3-none-any.whl failed, reason: getaddrinfo ENOTFOUND cdn.jsdelivr.net
The following error occurred while loading packaging:
request to https://cdn.jsdelivr.net/pyodide/v0.24.1/full/packaging-23.1-py3-none-any.whl failed, reason: getaddrinfo ENOTFOUND cdn.jsdelivr.net

@DDidas
Copy link

DDidas commented Mar 14, 2024

@DuelistRaj sorry for bothering you again. I did unpack the folder into node_modules and now there is a file named 'node_modules/pyodide/micropip-0.5.0-py3-none-any.whl'. But I still get the error 'Didn't find package micropip-0.5.0-py3-none-any.whl locally, attempting to load from https://cdn.jsdelivr.net/pyodide/v0.24.1/full/'! In my opinion it should find the file now, doesn't it? I just unpacked/copied the files into the project and ran 'npm run dump...' again, is that correct?

@DuelistRaj
Copy link

@DDidas I am assuming you downloaded the latest version of pyodide (v0.25). Make sure you have the correct release. Required is v0.24.1

@DuelistRaj
Copy link

DuelistRaj commented Mar 15, 2024

A better approach would be to host the pyodide files (make sure to download the release that is required) on a local server and replacing the cdn url in dump_artifacts.js found in node_modules/@stlite/desktop/bin with your localhost url.

return http://localhost:3000/pyodide/${e}

@whitphx
Copy link
Owner

whitphx commented May 30, 2024

Since 0.57.0, a new --pyodide-source option is available with the dump command, and you can specify a Pyodide package directory path or URL to download the files instead of the default CDN.
See https://github.com/whitphx/stlite/blob/main/packages/desktop/README.md#use-a-custom-pyodide-source for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants