electron-builder: /bin/sh command not found after building MacOS

  • Electron-Builder Version: 24.6.4
  • Node Version: 20.5.1
  • Electron Version: 26.2.1
  • Electron Type (current, beta, nightly): current
  • Target: MacOS

Seems to be related to #6726 in some way.

I’m trying to run some pip commands from my electron app using exec

(but same/similar issue with spawn and execa module as well)

Steps to reproduce:

  1. create project using template https://github.com/electron-react-boilerplate/electron-react-boilerplate
  2. Add this code in the main process (make sure to import exec and dialog correctly). You also need python installed for this (which I have installed in /Users/codergautam/.pyenv/shims/pip)
  // Run pip list command and show output in dialog
  exec('pip list', (err, stdout, stderr) => {
    console.log(stdout);
    console.log(stderr);
    if (err) {
      dialog.showErrorBox('Pip List Error', inspect(err));
      return;
    }
    dialog.showMessageBoxSync({
      title: 'Pip List',
      message: stdout.substring(0, 200),
    });
  });
  1. Run it using npm start, see the trimmed list of packages correctly
  2. Build it using npm run package then run the built app, you will get error:
Error: Command failed: pip list
/bin/sh: pip: command not found

at ChildProcess.exithandler (node:child_process:430:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at Socket.<anonymous> (node:internal/child_process:449:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:322:12) {
code: 127,
killed: false,
signal: null,
cmd: 'pip list'
}

Image: image

I think for some reason it’s trying to run the python 2.7 stuff which was removed. This is a major blocker, any way to fix?

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 2
  • Comments: 19

Most upvoted comments

Anything that is loaded from the user’s machine may or may not have their user profiles set up in the same way, so I would suggest against trying to load those files from code.

There’s a package that might be useful in this context: https://www.npmjs.com/package/python-shell

That all being said, I don’t know of a reliable way to load pip from within the app without it already being in the PATH.

When running npm run start, it is executing in your current terminal environment, which has all the settings of .profile/.bash_profile/.zshrc/etc. loaded.

A packaged application doesn’t have access to your user-profile

I meant to check the difference in process.env between runtime npm start and the bundled electron app. Doesn’t matter what the diff is between yarn and npm, only matters what the bundled electron app is able to access