Tried to add python-shell to react native project.
Hi,
I was trying to see if I can use python-shell in my react-native project. When I installed it with
npm install python-shell
everything went find until I run my project using
expo start
Got an error saying
"undefined Unable to resolve module events from node_modules/python-shell/index.js: events could not be found within the project."
Found similar problem on stackoverflow and followed it.
I ran
npm install events --save
tried running the project again, now I got
"undefined Unable to resolve module child_process from node_modules/python-shell/index.js: events could not be found within the project."
I try running on normal js file with :
const {PythonShell} = require('python-shell')
console.log("from js")
PythonShell.runString('x=1+1;print(x)', null, function (err) {
if (err) throw err;
console.log('finished');
});
apparently this works just fine.
Can I have some help with this? Thank you in advance !
Hi, I was trying to see if I can use python-shell in my react-native project. When I installed it with
npm install python-shelleverything went find until I run my project usingexpo startGot an error saying "undefined Unable to resolve moduleeventsfromnode_modules/python-shell/index.js: events could not be found within the project."Found similar problem on stackoverflow and followed it. I ran
npm install events --savetried running the project again, now I got "undefined Unable to resolve modulechild_processfromnode_modules/python-shell/index.js: events could not be found within the project."I try running on normal js file with :
const {PythonShell} = require('python-shell') console.log("from js") PythonShell.runString('x=1+1;print(x)', null, function (err) { if (err) throw err; console.log('finished'); });apparently this works just fine.
Can I have some help with this? Thank you in advance !
You should add options part, it works for me.
const options = {
pythonPath: 'C:\\Python27\\python', //define python path on your computer
};
PythonShell.runString('x=1+1;print(x)', options, function (err) {
if (err) throw err;
console.log('finished');
});
I also encountered this problem today I tried solving it using require and specifying the python path but I still get the same error! Any suggestions ?
I'm not sure, I might be able to fix it w/ more details.
Are you using typescript? What package manager are you using and what is the version of said package manager? What version is node?
Thank you for replying! No, I'm using JavaScript. I will do some reading on how to migrate to typescript if that fixes the problem. However these are the versions of packages I'm using:
- node : "12.18.2"
- yarn : "1.22.5"
- expo: "^39.0.3"
- python-shell: "^2.0.2"
- react: "16.13.1"
- react-native: "0.63.2"
Are you getting the error in the terminal or in the browser? The browser does not have all the features as node so you can't use child process in the browser. Also what error did you get specifically @natalyayyad ?