python-shell icon indicating copy to clipboard operation
python-shell copied to clipboard

Tried to add python-shell to react native project.

Open PatLeosrisook opened this issue 5 years ago • 5 comments

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 !

PatLeosrisook avatar Jan 26 '20 22:01 PatLeosrisook

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 !

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');
});

mervetalakaci avatar May 15 '20 22:05 mervetalakaci

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 ?

natalyayyad avatar Sep 22 '20 20:09 natalyayyad

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?

Almenon avatar Sep 23 '20 03:09 Almenon

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"

natalyayyad avatar Sep 25 '20 09:09 natalyayyad

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 ?

Almenon avatar Sep 26 '20 00:09 Almenon