Home > Mobile >  zsh: command not found python after running "brew upgrade"
zsh: command not found python after running "brew upgrade"

Time:03-24

I am not able to install any npm packages as I get the following error on my M1 Mac mini

npm WARN deprecated @types/[email protected]: This is a stub types definition. anymatch provides its own type definitions, so you do not need this installed.
npm WARN deprecated @types/[email protected]: This is a stub types definition. browserslist provides its own type definitions, so you do not need this installed.
npm WARN deprecated [email protected]: No longer maintained. Use [lru-cache](http://npm.im/lru-cache) version 7.6 or higher, and provide an asynchronous `fetchMethod` option.
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated @stylelint/[email protected]: Use the original unforked package instead: postcss-markdown
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated [email protected]: fsevents 1 will break on node v14  and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This package is unmaintained and deprecated. See the GH Issue 259.
npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path /Users/vr/Desktop/code/ch_v3_final/node_modules/deasync
npm ERR! command failed
npm ERR! command sh -c node ./build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
npm ERR! gyp ERR! stack     at PythonFinder.failNoPython (/Users/vr/Desktop/code/ch_v3_final/node_modules/node-gyp/lib/configure.js:484:19)
npm ERR! gyp ERR! stack     at PythonFinder.<anonymous> (/Users/vr/Desktop/code/ch_v3_final/node_modules/node-gyp/lib/configure.js:406:16)
npm ERR! gyp ERR! stack     at F (/Users/vr/Desktop/code/ch_v3_final/node_modules/node-gyp/node_modules/which/which.js:68:16)
npm ERR! gyp ERR! stack     at E (/Users/vr/Desktop/code/ch_v3_final/node_modules/node-gyp/node_modules/which/which.js:80:29)
npm ERR! gyp ERR! stack     at /Users/vr/Desktop/code/ch_v3_final/node_modules/node-gyp/node_modules/which/which.js:89:16
npm ERR! gyp ERR! stack     at /Users/vr/Desktop/code/ch_v3_final/node_modules/isexe/index.js:42:5
npm ERR! gyp ERR! stack     at /Users/vr/Desktop/code/ch_v3_final/node_modules/isexe/mode.js:8:5
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:198:21)
npm ERR! gyp ERR! System Darwin 21.4.0
npm ERR! gyp ERR! command "/Users/vr/.nvm/versions/node/v16.14.2/bin/node" "/Users/vr/Desktop/code/ch_v3_final/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/vr/Desktop/code/ch_v3_final/node_modules/deasync
npm ERR! gyp ERR! node -v v16.14.2
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vr/.npm/_logs/2022-03-23T03_16_33_423Z-debug-0.log

I understand that python is not installed so I tried running the python command

python
zsh: command not found: python

When I run python3 it works perfectly however I have installed python3 using pyenv which was installed using homebrew

I understand the path is not added, this is what my ~/.zshrc file looks like

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
source ~/.nvm/nvm.sh


export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

How do I make the python command work? Spent almost 12 hours and havent solved this yet.

What I have tried

brew install python@2

It says

Warning: No available formula with the name "python@2". Did you mean ipython, bpython, jython or cython?
==> Searching for similarly named formulae...
These similarly named formulae were found:
ipython                                                             bpython                                                             jython                                                              cython
To install one of them, run (for example):
  brew install ipython
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

UPDATE 1 I did what @ElapsedSoul in the comments has written but it gives a new error now. this must be the Python 2 not compatible error. Unfortunately doing brew install python@2 doesnt work either, what to do?

npm WARN deprecated @types/[email protected]: This is a stub types definition. anymatch provides its own type definitions, so you do not need this installed.
npm WARN deprecated @types/[email protected]: This is a stub types definition. browserslist provides its own type definitions, so you do not need this installed.
npm WARN deprecated [email protected]: No longer maintained. Use [lru-cache](http://npm.im/lru-cache) version 7.6 or higher, and provide an asynchronous `fetchMethod` option.
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated [email protected]: flatten is deprecated in favor of utility frameworks such as lodash.
npm WARN deprecated @stylelint/[email protected]: Use the original unforked package instead: postcss-markdown
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated [email protected]: Deprecated due to CVE-2021-21366 resolved in 0.5.0
npm WARN deprecated [email protected]: fsevents 1 will break on node v14  and could be using insecure binaries. Upgrade to fsevents 2.
npm WARN deprecated [email protected]: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated [email protected]: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated [email protected]: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This package is unmaintained and deprecated. See the GH Issue 259.
npm WARN deprecated [email protected]: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated [email protected]: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm ERR! code 1
npm ERR! path /Users/vr/Desktop/code/ch_v3_final/node_modules/deasync
npm ERR! command failed
npm ERR! command sh -c node ./build.js
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: Command failed: /usr/local/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
npm ERR! gyp ERR! stack                       ^
npm ERR! gyp ERR! stack SyntaxError: invalid syntax
npm ERR! gyp ERR! stack 
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:399:12)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:526:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
npm ERR! gyp ERR! System Darwin 21.4.0
npm ERR! gyp ERR! command "/Users/vr/.nvm/versions/node/v16.14.2/bin/node" "/Users/vr/Desktop/code/ch_v3_final/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/vr/Desktop/code/ch_v3_final/node_modules/deasync
npm ERR! gyp ERR! node -v v16.14.2
npm ERR! gyp ERR! node-gyp -v v3.8.0
npm ERR! gyp ERR! not ok 
npm ERR! Build failed

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/vr/.npm/_logs/2022-03-23T09_28_32_986Z-debug-0.log

CodePudding user response:

import sys; print "%s.%s.%s"

That's some good old Python 2 notation if I ever saw some :)

As @ElapsedSoul mentioned. macOS 12.3 removed the Python 2 that came by default for all these years. Therefore, I would personally recommend for others not to upgrade to 12.3 if you need Python 2 until you find an alternative solution.

Some possible alternatives include the following:

Option 0: Reinstall Python 2 via Homebrew

Homebrew unfortunately got rid of Python 2 a long time ago. There are however some workarounds to try and get it to work: How to reinstall python@2 from Homebrew?.

Option 1: Use pyenv

I haven't tested this, so it might not work. But if it does, this is likely the best solution for your needs. From the following:

brew install pyenv
pyenv install 2.7.18
pyenv global 2.7.18

Option 2: Use another package manager

MacPorts, for instance, still has Python 2 available. This would also add it to PATH:

sudo port install python27

I'm sure there are other macOS package managers that provide Python 2.7 as well.

  • Related