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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to integrate in a React Native app? #2343

Open
gkaissis opened this issue Apr 2, 2022 · 7 comments
Open

How to integrate in a React Native app? #2343

gkaissis opened this issue Apr 2, 2022 · 7 comments

Comments

@gkaissis
Copy link

gkaissis commented Apr 2, 2022

馃摎 Documentation

It would be great to have some documentation on how to initialize and run Pyodide on mobile devices using React Native. I've tried several methods, but none seems to work satisfactorily. With Tensorflow for React Native being a thing, RN is probably the closest platform to being "ready" for data science on mobile. Thanks!

@gkaissis gkaissis changed the title Document integration in React Native How to integrate in a React Native app? Apr 3, 2022
@gkaissis
Copy link
Author

Any news on this? I am no expert but it seems it should be possible somehow and only in need of some documentation.

@rth
Copy link
Member

rth commented May 23, 2022

Well, none of the maintainers use React Native as far as I know. So we are certainly interested if feedback and contributions on this subject but can't answer your question about how to integrate with React Native. Also see the related issue in #2549 There is currently work on improving the npm package discussed in #2403

@gkaissis
Copy link
Author

Many thanks!

@StephDC
Copy link

StephDC commented Apr 12, 2023

Any further news on this?

All my attempt to import pyodide failed in the call to import(url) in React Native, which sounds like that the pyodide had to find the source of the other assets but unable to find them.

I switched to React Native -> chaquopy for now, but if there is anything that worth a test with the React Native -> Pyodide thing please let me know.

@rth
Copy link
Member

rth commented Apr 12, 2023

Can you share the detailed error message? Normally the package on NPM should have everything needed for a base setup, and then it would download packages on runtime but it's possible that something would need to be adjusted for this use case.

@StephDC
Copy link

StephDC commented Apr 12, 2023

Error message:

error: node_modules/pyodide/pyodide.js: node_modules/pyodide/pyodide.js:Invalid call at line 1: import( /* webpackIgnore: true */url)

Sample code to setup the environment:

npx react-native init MyApp
cd MyApp
npm install --save pyodide

Modify the App.tsx by adding the following two lines at the top:

import {loadPython} from 'pyodide';
loadPython();

Then run the app with the following:

npx react-native start

and press a to start Android.

I have tried to webpack build and import the webpack one, and it is still the same error message. I am also not using react-py as it requires Worker but Worker is not available by default and it complicates things more.

@elilambnz
Copy link
Contributor

@StephDC you could attempt to use a much older version of react-py before web workers were implemented. I think 1.0.8 is the latest release before this point.

I don't have the capacity to test this now, but if you have any luck with this direction please open a feature request on the react-py repo to optionally disable web workers.

@rth rth added the Sprint label Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants