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

Installing Packages for predicted_output_choices #482

Open
HannahKn123 opened this issue Sep 2, 2024 · 4 comments
Open

Installing Packages for predicted_output_choices #482

HannahKn123 opened this issue Sep 2, 2024 · 4 comments

Comments

@HannahKn123
Copy link

Hello,

I am experimenting with the code and would like to create a quiz with predicted_output_choices. Part of the quiz should be to initialize a numpy array and the choices should be 4 different arrays a a output.

For this I have to install numpy in the backend. Unfortunately there are problems if I install numpy in the back end, because then I can't install numpy directly in the futurecoder. The following error message appears:

Error traceback:
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
A ModuleNotFoundError exception indicates that you are trying to import a module that cannot be found by Python. This could be because you misspelled the name of the module or because it is not installed on your computer.

No module named numpy.core._multiarray_umath can be imported. Perhaps you need to install it.

Click to expand
During handling of the above exception, another exception occurred:
1 import numpy as np
ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.11 from "/home/pyodide/this.program" * The NumPy version is: "1.24.2" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No module named 'numpy.core._multiarray_umath'

Does anyone have an idea how I can work around this problem?
Thank you!

@oskarissimus
Copy link
Contributor

How exactly did you install numpy? I think there is a specific way in which packages are installed int pyodide
https://pyodide.org/en/stable/usage/loading-packages.html

@HannahKn123
Copy link
Author

HannahKn123 commented Sep 2, 2024 via email

@oskarissimus
Copy link
Contributor

oskarissimus commented Sep 2, 2024

I think that installing numpy with poetry won't be enough. Pyodide - the thing that makes python work in browser - has its own packages. See the example below on how dependences are added to pyodide

const checkerModule = pyodide.pyimport("core.checker");

I might be wrong tho

@alexmojaki
Copy link
Owner

It's true that you need to load numpy specially within pyodide. Try adding await pyodide.loadPackage("numpy") here:

const reloader = new PyodideFatalErrorReloader(async () => {
const pyodide = await loadPyodideAndPackage({url: pythonCoreUrl, format: "tar"});
pyodide.pyimport("core.init_pyodide").init(process.env.REACT_APP_LANGUAGE);
return pyodide;
});

But you do also need to install it with poetry and import it to generate static files. And this is the first time that there's a dependency that isn't pure Python and has to be loaded differently in the two environments. Ensure numpy isn't added to roots here:

if root == "_distutils_hack":
continue
roots.add(root)

This will prevent it from being added to python_core.tar.load_by_url so that it should be imported from the pyodide installation.

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

No branches or pull requests

3 participants