extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.12k stars 224 forks source link

Permission denied error in Alpine Linux #270

Open christopherpickering opened 2 years ago

christopherpickering commented 2 years ago

Hi, Probably the answer is simple :) I'm trying to run in Alpine Linux to install a package and get a permission denied errno 13.

Oddly, some packages install ok, and some have the permission denied. For example if you use this to install the requests module, it works. The python error suggest adding the --user flag, but that doesn't help here.

Here's how to produce it:


# start up docker alpine + node
docker run --rm -it node:18-alpine /bin/sh 

# start a project
mkdir test && cd test && npm init -y && npm i python-shell

# install python and pip
apk add python3
apk add py3-pip

# make a script
cat > index.js<< EOF
const { PythonShell } = require('python-shell');

PythonShell.defaultOptions = {};
const options = {
  mode: 'text',
  args: ['pip', 'install', 'pandas'],
  pythonOptions: ['-u'],
  env: { PYCHARM_HOSTED: 1 },
};

try {
  PythonShell.getVersionSync();

  PythonShell.run('-m', options, function (error, results) {
    if (error) throw error;
    console.log(results.join('\n'));
  });
} catch(e) {
  console.log(e);
  process.exit(1)
}
EOF

# run the script
node ./index.js

You can run python3 -m pip install pandas from the terminal without problem.

I suppose it is doing something in system folder.

Here's the error:

/test # node ./index.js
/test/index.js:15
    if (error) throw error;
               ^

PythonShellError:   ERROR: Error [Errno 13] Permission denied: '' while executing command pip subprocess to install build dependencies
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: ''
Consider using the `--user` option or check the permissions.

    at PythonShell.parseError (/test/node_modules/python-shell/index.js:303:21)
    at terminateIfNeeded (/test/node_modules/python-shell/index.js:190:32)
    at ChildProcess.<anonymous> (/test/node_modules/python-shell/index.js:182:13)
    at ChildProcess.emit (node:events:537:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12) {
  executable: 'python3',
  options: [ '-u' ],
  script: '-m',
  args: [ 'pip', 'install', 'pandas' ],
  exitCode: 1
}

Node.js v18.4.0

Any ideas are appreciated!

Almenon commented 2 years ago

This is very weird... Good find, not sure what's up with this.

Pandas is failing to install even with just python inside that docker image, do you have any other libraries that can be used to reproduce this error?

christopherpickering commented 2 years ago

@Almenon not offhand, I just picked a couple of the top librarys to test.