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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit code: ENOENT. spawn /usr/bin/python error after updating macOS #6726

Closed
helderjbe opened this issue Mar 17, 2022 · 24 comments
Closed

Exit code: ENOENT. spawn /usr/bin/python error after updating macOS #6726

helderjbe opened this issue Mar 17, 2022 · 24 comments
Labels

Comments

@helderjbe
Copy link

  • Electron-Builder Version: 22.14.13
  • Node Version: 16.13.2
  • Electron Version: 17.1.2
  • Electron Type (current, beta, nightly): current
  • Target: universal

I recently updated my MacBook Air M1 (macOS Monterey) to 12.3 and started receiving this error when running "electron-builder":

  • electron-builder  version=22.14.13 os=21.4.0
  • loaded configuration  file=package.json ("build" field)
  • writing effective config  file=dist/builder-effective-config.yaml
  • packaging       platform=darwin arch=arm64 electron=17.1.2 appOutDir=dist/mac-arm64
  • default Electron icon is used  reason=application icon is not set
  • skipped macOS application code signing  reason=cannot find valid "Developer ID Application" identity or custom non-Apple code signing certificate, it could cause some undefined behaviour, e.g. macOS localized description not visible, see https://electron.build/code-signing allIdentities=     0 identities found
                                                Valid identities only
     0 valid identities found
  • building        target=macOS zip arch=arm64 file=dist/my-app-0.2.0-arm64-mac.zip
  • building        target=DMG arch=arm64 file=dist/my-app-0.2.0-arm64.dmg
  • Detected arm64 process, HFS+ is unavailable. Creating dmg with APFS - supports Mac OSX 10.12+
  • building block map  blockMapFile=dist/my-app-0.2.0-arm64-mac.zip.blockmap
  ⨯ Exit code: ENOENT. spawn /usr/bin/python ENOENT  failedTask=build stackTrace=Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT
    at /Users/helder/Documents/patientdiary/node_modules/builder-util/src/util.ts:133:18
    at exithandler (node:child_process:404:5)
    at ChildProcess.errorhandler (node:child_process:416:5)
    at ChildProcess.emit (node:events:390:28)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:288:12)
    at onErrorNT (node:internal/child_process:477:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
@scowalt
Copy link

scowalt commented Mar 17, 2022

I'm investigating this issue right now since it's blocking my work. Here's what I've learned:

  • builder-util is trying to call python because the package dmg-builder uses python scripts
  • You can set the environment variable PYTHON_PATH to overwrite the default of /usr/bin/python, however:
  • dmg-builder uses the reload module, which is only available builtin in Python 2

So presumably, setting PYTHON_PATH to a python2 installation could work around this issue. I'll be trying that next.

@scowalt
Copy link

scowalt commented Mar 17, 2022

FYI, this may be a dupe of #6606

@helderjbe
Copy link
Author

FYI, this may be a dupe of #6606

You are right, upgrading to 23.0.2 fixed this issue.

I had searched for this for some time but I couldn't find anything, thanks for the help!

Naozumi520 pushed a commit to Naozumi520/Remedy that referenced this issue Mar 19, 2022
@fttx
Copy link

fttx commented Mar 19, 2022

@scowalt did you manage to make it work by setting the PYTHON_PATH? I can't update electron-builder because it'll break other things

@lylyong
Copy link

lylyong commented Mar 20, 2022

FYI, this may be a dupe of #6606

You are right, upgrading to 23.0.2 fixed this issue.

I had searched for this for some time but I couldn't find anything, thanks for the help!

how to upgrade 23.0.2

@helderjbe
Copy link
Author

npm install [email protected]

@hjMaGitHub
Copy link

Hello, it is already 23.0.2, but still reported an error, do you have any suggestions?
image

@hjMaGitHub
Copy link

Hello, it is already 23.0.2, but still reported an error, do you have any suggestions?

@scowalt
Copy link

scowalt commented Mar 20, 2022

@scowalt did you manage to make it work by setting the PYTHON_PATH? I can't update electron-builder because it'll break other things

I ended up just updating electron-builder, so I never finished testing PYTHON_PATH.


@hjMaGitHub , it looks like vue-cli-plugin-electron-builder is still potentially using an old version of electron-builder. If you use Yarn, you can use selective dependency resolutions to force that module to use the newer electron-builder. I don't know how to do that with NPM

@lylyong
Copy link

lylyong commented Apr 13, 2022

if you use yarn,after install python2.7.18 and fix the python's path, you can add this code in package.json to fix it
"dependencies": {
....
}
"devDependencies": {
...
}
"resolutions": {
"vue-cli-plugin-electron-builder/electron-builder": "^23.0.3"
}

yarn is ok, I'm not try it in npm

@MarMun
Copy link

MarMun commented Apr 14, 2022

yarn is ok, I'm not try it in npm

npm (native) solution to this are npm overrides. See example here.

@samowolabi
Copy link

This should work 😁.
Go to node_modules/dmg-builder/out/dmg.js.
In "dmg.js" file, search replace "usr/bin/python" to "usr/bin/python2".

*Note: Python v2 must be installed, and check if this directory exists by pressing "sudo cd usr/bin/python2".

  • The reason why this error exists "Exit code: ENOENT. spawn /usr/bin/python" is because "ENOENT" means no existing directory. The version of the python cant be found.

@Jayin
Copy link

Jayin commented Apr 15, 2022

+1

@renepardon
Copy link

I had just "vue-cli-plugin-electron-builder": "~2.1.1" installed. After adding "electron-builder": "^23.0.3", as additional dependency the error was gone and build works.

@robertmassman
Copy link

After updating electron-builder I had to updating dmg-builder to successfully fix dmg creation.

@tkarnaAWS
Copy link

@NiksolazLogix
Copy link

thx @lylyong the resolution "vue-cli-plugin-electron-builder/electron-builder": "^23.0.3" is very great

@camellieeee
Copy link

May be change dmg.js and dmg.js.map can solute the problem. /usr/bin/python -> python2
1
2

@willian12345
Copy link

python2

As on my Mac, It works after next steps

  1. find the python2 real path use which python in terminal after reinstall python2, It will be like /Library/Frameworks/Python.framework/Versions/2.7/bin/python
  2. open /node_modules/dmg-builder/out/dmg.js In your project
  3. Use /Library/Frameworks/Python.framework/Versions/2.7/bin/python replace "/usr/bin/python" in dmg.js
  4. Save it

NeonGamerBot-QK added a commit to NeonGamerBot-QK/Annotationapp that referenced this issue Mar 26, 2023
This fixes the error with building in macos
more info here: electron-userland/electron-builder#6726
gimKondo added a commit to gimKondo/sound-of-cthulhu that referenced this issue May 4, 2023
undergroundwires added a commit to undergroundwires/privacy.sexy that referenced this issue Jul 31, 2023
The GitHub-hosted runners began experiencing issues while building macOS
desktop distributions, exclusively affecting the macOS environment.
The Ubuntu and Windows environments remained unaffected.

The logs highlighted the absence of Python in the macOS environment, which
resulted in build failure:

```sh
  Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT
```

Since the `electron-builder` package uses Python scripts to create DMG
disk images for macOS distributions, Python is needed for building the
application. However, electron-builder uses Python 2.X meanwhile modern
macOS versions have removed Python 2.X from the operating system on
default installation.

Although this issue was resolved in `electron-builder` version 23,,
`vue-cli-plugin-electron-builder` continues to use version 22. Due to a
lack of maintenance, the package is unlikely to receive updates.

This commit forces `vue-cli-plugin-electron-builder` to use the latest
`electron-builder` which resolves the macOS distribution build failure.

In CI process, GitHub-hosted runners start to fail when building macOS
desktop distributions. It is only observered in the macOS environment
while the application is built successfully in both the Ubuntu and
Windows environments.

The error message in the logs indicated that Python was not found in the
macOS environment:

```sh
Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT
```

`electron-builder` package uses Python scripts for certain operations,
specifically for creating DMG disk images for macOS distributions. As a
result, Python is a necessary dependency when building the application
for macOS.

`electron-builder` has fixed this starting from version 23, but
vue-cli-plugin-electron-builder still refers to version 22 and it is
unmaintained and not likely to get updates.

The solution is to add a step in the GitHub Actions workflow to set up
Python in the macOS environment. `actions/setup-python` sets up the
Python environment in the runner if the OS is macOS.

This change does not impact the Ubuntu and Windows environments as the
setup-python step is conditionally executed only for macOS. The addition
of Python to the macOS environment in CI process has resolved the build
failure issue for the macOS distribution.

See also:

- electron-userland/electron-builder#6606
- electron-userland/electron-builder#6726
- electron-userland/electron-builder#6732
- nklayman/vue-cli-plugin-electron-builder#1691
- nklayman/vue-cli-plugin-electron-builder#1701
Offroaders123 added a commit to Offroaders123/Electron-Text-Editor that referenced this issue Sep 24, 2023
I also updates the `package-lock.json` to the v3 format. Now the app compiles again, too! Looks like I ran into this issue with Electron-Builder here, I'm pretty sure.

electron-userland/electron-builder#6726
LarrMarburger added a commit to LarrMarburger/privacy.sexy that referenced this issue Nov 16, 2023
The GitHub-hosted runners began experiencing issues while building macOS
desktop distributions, exclusively affecting the macOS environment.
The Ubuntu and Windows environments remained unaffected.

The logs highlighted the absence of Python in the macOS environment, which
resulted in build failure:

```sh
  Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT
```

Since the `electron-builder` package uses Python scripts to create DMG
disk images for macOS distributions, Python is needed for building the
application. However, electron-builder uses Python 2.X meanwhile modern
macOS versions have removed Python 2.X from the operating system on
default installation.

Although this issue was resolved in `electron-builder` version 23,,
`vue-cli-plugin-electron-builder` continues to use version 22. Due to a
lack of maintenance, the package is unlikely to receive updates.

This commit forces `vue-cli-plugin-electron-builder` to use the latest
`electron-builder` which resolves the macOS distribution build failure.

In CI process, GitHub-hosted runners start to fail when building macOS
desktop distributions. It is only observered in the macOS environment
while the application is built successfully in both the Ubuntu and
Windows environments.

The error message in the logs indicated that Python was not found in the
macOS environment:

```sh
Error: Exit code: ENOENT. spawn /usr/bin/python ENOENT
```

`electron-builder` package uses Python scripts for certain operations,
specifically for creating DMG disk images for macOS distributions. As a
result, Python is a necessary dependency when building the application
for macOS.

`electron-builder` has fixed this starting from version 23, but
vue-cli-plugin-electron-builder still refers to version 22 and it is
unmaintained and not likely to get updates.

The solution is to add a step in the GitHub Actions workflow to set up
Python in the macOS environment. `actions/setup-python` sets up the
Python environment in the runner if the OS is macOS.

This change does not impact the Ubuntu and Windows environments as the
setup-python step is conditionally executed only for macOS. The addition
of Python to the macOS environment in CI process has resolved the build
failure issue for the macOS distribution.

See also:

- electron-userland/electron-builder#6606
- electron-userland/electron-builder#6726
- electron-userland/electron-builder#6732
- nklayman/vue-cli-plugin-electron-builder#1691
- nklayman/vue-cli-plugin-electron-builder#1701
@FotieMConstant
Copy link

FotieMConstant commented Jan 30, 2024

2024 and none of the mentioned solutions above worked for me.
For anyone out there still facing this issue till today.
If you are on Apple silicon M1/M2 or M3, you might want to do this.

PS: i am using the eletron-builder in a vuejs app, just FYI

Problem: Firstly, this is a python problem like mentioned above, however since MacOS doesn't ship with default python anymore it's an issue. It seems like the "vue-cli-plugin-electron-builder": "~2.1.1" package hasn't been updated yet with the latest builder version which as of today is "electron-builder": "^24.9.1",. and it appears the version vue-cli-plugin-electron-builder is not yet compatible with the the new arm64 architecture.

Solution:

  • install electron-builder with npm i electron-builder
  • update your package.json with the code below. This forces override via npm:
    // other dev dependencies
    "vue-cli-plugin-electron-builder": "~2.1.1"
  },
  "overrides": {
    "vue-cli-plugin-electron-builder": {
      "electron-builder": "^23.0.6"
    }
  }

Works like charm✨

PS: Another untested solution which could theoretically work is, you should find a way to install python 2.x (I think) and update the environment variables so it can find it in the path usr/bin/python

@async-promise
Copy link

which python

/Users/async/.pyenv/shims/python

export PYTHON_PATH=/Users/async/.pyenv/shims/python

npm run build:xxx...

Find the python path on your machine and export PYTHON_PATH when npm run build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests