Skip to content

node-gyp configure error "Python is not set from command line or npm configuration" #2664

Closed

Description

@mluce194
  • Node Version: Node 17.4.0 npm 8.3.1
  • Platform: Darwin Kernel Version 18.7.0
  • Compiler: Apple LLVM version 10.0.1 (clang-1001.0.46.4)
    Target: x86_64-apple-darwin18.7.0
    Thread model: posix
  • Module: Gatsby Website

node-gyp configure

gyp info using node-gyp@9.0.0
gyp info using node@17.4.0 | darwin | x64
gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - executable path is "/usr/bin/python"
gyp ERR! find Python - version is "2.7.16"
gyp ERR! find Python - version is 2.7.16 - should be >=3.6.0
gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
gyp ERR! find Python 
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python 
gyp ERR! configure error 
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:266:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:297:7)
gyp ERR! stack     at ChildProcess.exithandler (node:child_process:390:7)
gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
gyp ERR! stack     at maybeClose (node:internal/child_process:1090:16)
gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:449:11)
gyp ERR! stack     at Socket.emit (node:events:520:28)
gyp ERR! stack     at Pipe.<anonymous> (node:net:687:12)
gyp ERR! System Darwin 18.7.0
gyp ERR! command "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node" "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node-gyp" "configure"
gyp ERR! cwd /Users/marie-luce/Documents/projets/projet/2022/website.com gatsby contentful
gyp ERR! node -v v17.4.0
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok ```






</details>

Originally, I had an issue with node-gyp when trying to build a Gatsby Website. I tried node-gyp configure and got this error.

Activity

  1. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    gyp ERR! find Python - version is 2.7.16 - should be >=3.6.0

    Python 2 died 862 days ago on 1/1/2020 so it is no longer supported.

    You need a supported version of Python: https://devguide.python.org/#status-of-python-branches

    On your Mac, please let us know what it says when you do:
    % sw_vers

  2. mluce194 commented on May 12, 2022

    @mluce194
    Author

    I installed Python3 with Brew but it either did not work or node-gyp does not seem to find it.
    This is what I get when I type sw_vers on my terminal:

    ProductName:	Mac OS X
    ProductVersion:	10.14.6
    BuildVersion:	18G9323
    
  3. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    Mine says:

    ProductName:	macOS
    ProductVersion:	12.3.1
    BuildVersion:	21E258
    

    so you are on an older macOS. What do you get when you type:

    which -a python3
    brew list | grep python
    python3 --version
    
  4. mluce194 commented on May 12, 2022

    @mluce194
    Author

    It says:
    python@3.10

  5. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    Please try to add to your command:

    • --python=python3 or
    • --python=python3.10 or
    • --python="/usr/local/homebrew/opt/python@3.10/bin/python3"

    Like:

    node-gyp --python=python3 configure
    
  6. mluce194 commented on May 12, 2022

    @mluce194
    Author

    I tried the 3 commands listed but I always get the same error:

    gyp ERR! find Python 
    gyp ERR! find Python checking Python explicitly set from command line or npm configuration
    gyp ERR! find Python - "--python=" or "npm config get python" is "python3"
    gyp ERR! find Python - "python3" is not in PATH or produced an error
    gyp ERR! find Python Python is not set from environment variable PYTHON
    gyp ERR! find Python checking if "python3" can be used
    gyp ERR! find Python - "python3" is not in PATH or produced an error
    gyp ERR! find Python checking if "python" can be used
    gyp ERR! find Python - executable path is "/usr/bin/python"
    gyp ERR! find Python - version is "2.7.16"
    gyp ERR! find Python - version is 2.7.16 - should be >=3.6.0
    gyp ERR! find Python - THIS VERSION OF PYTHON IS NOT SUPPORTED
    gyp ERR! find Python 
    gyp ERR! find Python **********************************************************
    gyp ERR! find Python You need to install the latest version of Python.
    gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
    gyp ERR! find Python you can try one of the following options:
    gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
    gyp ERR! find Python   (accepted by both node-gyp and npm)
    gyp ERR! find Python - Set the environment variable PYTHON
    gyp ERR! find Python - Set the npm configuration variable python:
    gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
    gyp ERR! find Python For more information consult the documentation at:
    gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
    gyp ERR! find Python **********************************************************
    gyp ERR! find Python 
    gyp ERR! configure error 
    gyp ERR! stack Error: Could not find any Python installation to use
    gyp ERR! stack     at PythonFinder.fail (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:330:47)
    gyp ERR! stack     at PythonFinder.runChecks (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:159:21)
    gyp ERR! stack     at PythonFinder.<anonymous> (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:266:16)
    gyp ERR! stack     at PythonFinder.execFileCallback (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/find-python.js:297:7)
    gyp ERR! stack     at ChildProcess.exithandler (node:child_process:390:7)
    gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
    gyp ERR! stack     at maybeClose (node:internal/child_process:1090:16)
    gyp ERR! stack     at Socket.<anonymous> (node:internal/child_process:449:11)
    gyp ERR! stack     at Socket.emit (node:events:520:28)
    gyp ERR! stack     at Pipe.<anonymous> (node:net:687:12)
    gyp ERR! System Darwin 18.7.0
    gyp ERR! command "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node" "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node-gyp" "--python=python3" "configure"
    gyp ERR! cwd /Users/marie-luce/Documents/projets/paul-marie/2022/beraudo.com gatsby contentful
    gyp ERR! node -v v17.4.0
    gyp ERR! node-gyp -v v9.0.0
    gyp ERR! not ok
    

    This is weird because I installed python3 but I cannot find the path to it on my mac. When I type which python3 on my terminal, I do not get any result.

  7. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    brew doctor
    brew list | grep python
    brew info python@3.10

  8. mluce194 commented on May 12, 2022

    @mluce194
    Author

    This is what I get when I run info python@3.10:

    python@3.10: stable 3.10.4 [keg-only]
    Interpreted, interactive, object-oriented programming language
    https://www.python.org/
    /usr/local/Cellar/python@3.10/3.10.4 (7,968 files, 119.8MB)
      Built from source on 2022-05-12 at 09:33:27
    From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/python@3.10.rb
    License: Python-2.0
    ==> Dependencies
    Build: pkg-config ✔
    Required: gdbm ✔, mpdecimal ✔, openssl@1.1 ✔, readline ✔, sqlite ✔, xz ✔
    ==> Caveats
    Python has been installed as
      /usr/local/opt/python@3.10/bin/python3
    
    Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
    `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
      /usr/local/opt/python@3.10/libexec/bin
    
    You can install Python packages with
      /usr/local/opt/python@3.10/bin/pip3 install <package>
    They will install into the site-package directory
      /usr/local/lib/python3.10/site-packages
    
    tkinter is no longer included with this formula, but it is available separately:
      brew install python-tk@3.10
    
    See: https://docs.brew.sh/Homebrew-and-Python
    
    python@3.10 is keg-only, which means it was not symlinked into /usr/local,
    because this is an alternate version of another formula.
    
    If you need to have python@3.10 first in your PATH, run:
      echo 'export PATH="/usr/local/opt/python@3.10/bin:$PATH"' >> /Users/marie-luce/.bash_profile
    
    For compilers to find python@3.10 you may need to set:
      export LDFLAGS="-L/usr/local/opt/python@3.10/lib"
    
    For pkg-config to find python@3.10 you may need to set:
      export PKG_CONFIG_PATH="/usr/local/opt/python@3.10/lib/pkgconfig"
    
    ==> Analytics
    install: 376,493 (30 days), 1,002,168 (90 days), 2,300,695 (365 days)
    install-on-request: 102,499 (30 days), 261,181 (90 days), 394,530 (365 days)
    build-error: 358 (30 days)
    
  9. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    Do this...

    If you need to have python@3.10 first in your PATH, run:
    echo 'export PATH="/usr/local/opt/python@3.10/bin:$PATH"' >> /Users/marie-luce/.bash_profile

    Open a new terminal window / tab and then python3 --version

  10. mluce194 commented on May 12, 2022

    @mluce194
    Author

    Opening a new terminal did make things better. When I enter python3 --version I get:
    Python 3.10.4
    When I run node-gyp configure,it gets better but I still have an error:

    gyp info it worked if it ends with ok
    gyp info using node-gyp@9.0.0
    gyp info using node@17.4.0 | darwin | x64
    gyp info find Python using Python version 3.10.4 found at "/usr/local/opt/python@3.10/bin/python3.10"
    gyp http GET https://nodejs.org/download/release/v17.4.0/node-v17.4.0-headers.tar.gz
    gyp http 200 https://nodejs.org/download/release/v17.4.0/node-v17.4.0-headers.tar.gz
    gyp http GET https://nodejs.org/download/release/v17.4.0/SHASUMS256.txt
    gyp http 200 https://nodejs.org/download/release/v17.4.0/SHASUMS256.txt
    gyp info spawn /usr/local/opt/python@3.10/bin/python3.10
    gyp info spawn args [
    gyp info spawn args   '/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/gyp/gyp_main.py',
    gyp info spawn args   'binding.gyp',
    gyp info spawn args   '-f',
    gyp info spawn args   'make',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/marie-luce/Documents/projets/paul-marie/2022/beraudo.com gatsby contentful/build/config.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/addon.gypi',
    gyp info spawn args   '-I',
    gyp info spawn args   '/Users/marie-luce/Library/Caches/node-gyp/17.4.0/include/node/common.gypi',
    gyp info spawn args   '-Dlibrary=shared_library',
    gyp info spawn args   '-Dvisibility=default',
    gyp info spawn args   '-Dnode_root_dir=/Users/marie-luce/Library/Caches/node-gyp/17.4.0',
    gyp info spawn args   '-Dnode_gyp_dir=/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp',
    gyp info spawn args   '-Dnode_lib_file=/Users/marie-luce/Library/Caches/node-gyp/17.4.0/<(target_arch)/node.lib',
    gyp info spawn args   '-Dmodule_root_dir=/Users/marie-luce/Documents/projets/paul-marie/2022/beraudo.com gatsby contentful',
    gyp info spawn args   '-Dnode_engine=v8',
    gyp info spawn args   '--depth=.',
    gyp info spawn args   '--no-parallel',
    gyp info spawn args   '--generator-output',
    gyp info spawn args   'build',
    gyp info spawn args   '-Goutput_dir=.'
    gyp info spawn args ]
    gyp: binding.gyp not found (cwd: /Users/marie-luce/Documents/projets/paul-marie/2022/beraudo.com gatsby contentful) while trying to load binding.gyp
    gyp ERR! configure error 
    gyp ERR! stack Error: `gyp` failed with exit code: 1
    gyp ERR! stack     at ChildProcess.onCpExit (/Users/marie-luce/.nvm/versions/node/v17.4.0/lib/node_modules/node-gyp/lib/configure.js:261:16)
    gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
    gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
    gyp ERR! System Darwin 18.7.0
    gyp ERR! command "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node" "/Users/marie-luce/.nvm/versions/node/v17.4.0/bin/node-gyp" "configure"
    gyp ERR! cwd /Users/marie-luce/Documents/projets/paul-marie/2022/beraudo.com gatsby contentful
    gyp ERR! node -v v17.4.0
    gyp ERR! node-gyp -v v9.0.0
    gyp ERR! not ok
    
  11. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    Much better.

    gyp: binding.gyp not found

    You need that file even if it is empty.

  12. mluce194 commented on May 12, 2022

    @mluce194
    Author

    Thanks, it worked!

  13. cclauss commented on May 12, 2022

    @cclauss
    Contributor

    The Python@3.10 thing is about https://stackoverflow.com/questions/70587544

  14. Rihyx commented on Dec 20, 2022

    @Rihyx

    How I fixed the issue.

    $ brew install python3

    Then fix .zshrc:
    $ open ~/.zshrc

    And add:

    # Add python from brew
    alias python3="/opt/homebrew/bin/python3"
    # to fix NPM
    export PYTHON="/opt/homebrew/bin/python3"
    
  15. cclauss commented on Dec 20, 2022

    @cclauss
    Contributor

    If you had to do alias python3="/opt/homebrew/bin/python3" the brew is not properly configured and you might want to brew doctor

  16. diegomarcuz commented on Nov 13, 2023

    @diegomarcuz

    binding.gyp

    @cclauss where should I create this file?

  17. lakhan-atg commented on May 29, 2024

    @lakhan-atg

    gyp ERR! find Python Python is not set from command line or npm configuration gyp ERR! find Python Python is not set from environment variable PYTHON gyp ERR! find Python checking if "python3" can be used gyp ERR! find Python - "python3" is not in PATH or produced an error gyp ERR! find Python checking if "python" can be used gyp ERR! find Python - "python" is not in PATH or produced an error gyp ERR! find Python gyp ERR! find Python ********************************************************** gyp ERR! find Python You need to install the latest version of Python. gyp ERR! find Python Node-gyp should be able to find and use Python. If not, gyp ERR! find Python you can try one of the following options: gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable" gyp ERR! find Python (accepted by both node-gyp and npm) gyp ERR! find Python - Set the environment variable PYTHON gyp ERR! find Python - Set the npm configuration variable python: gyp ERR! find Python npm config set python "/path/to/pythonexecutable" gyp ERR! find Python For more information consult the documentation at: gyp ERR! find Python https://github.com/nodejs/node-gyp#installation

  18. arrmani88 commented on Dec 20, 2024

    @arrmani88

    In my case, I just had to downgrade node:

    $ npm install -g n
    $ n 14.21.3 // you need to figure out what specific version you need
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions