ValueError: invalid mode: 'rU' while trying to load binding.gyp (Python 3.9 compatibility issue)
See original GitHub issue- Node Version: 13.7.0
- Platform: Windows
- Module: binding.gyp
Verbose output (from npm or node-gyp):
gyp info it worked if it ends with ok
gyp verb cli [
gyp verb cli 'C:\\Program Files\\nodejs\\node.exe',
gyp verb cli 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js',
gyp verb cli 'configure',
gyp verb cli '--verbose'
gyp verb cli ]
gyp info using node-gyp@7.1.0
gyp info using node@13.7.0 | win32 | x64
gyp verb command configure []
gyp verb find Python Python is not set from command line or npm configuration
gyp verb find Python Python is not set from environment variable PYTHON
gyp verb find Python checking if "python3" can be used
gyp verb find Python - executing "python3" to get executable path
gyp verb find Python - "python3" is not in PATH or produced an error
gyp verb find Python checking if "python" can be used
gyp verb find Python - executing "python" to get executable path
gyp verb find Python - executable path is "C:\Python39\python.exe"
gyp verb find Python - executing "C:\Python39\python.exe" to get version
gyp verb find Python - version is "3.9.0"
gyp info find Python using Python version 3.9.0 found at "C:\Python39\python.exe"
gyp verb get node dir no --target version specified, falling back to host node version: 13.7.0
gyp verb command install [ '13.7.0' ]
gyp verb install input version string "13.7.0"
gyp verb install installing version: 13.7.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 13.7.0
gyp verb build dir attempting to create "build" dir: C:\cpp\screenshot\build
gyp verb build dir "build" dir needed to be created? undefined
gyp verb find VS msvs_version not set from command line or npm config
gyp verb find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp verb find VS checking VS2017 (15.9.28307.1259) found at:
gyp verb find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
gyp verb find VS - found "Visual Studio C++ core features"
gyp verb find VS - found VC++ toolset: v141
gyp verb find VS - found Windows SDK: 10.0.17763.0
gyp info find VS using VS2017 (15.9.28307.1259) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
gyp info find VS run with --verbose for detailed information
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: C:\cpp\screenshot\build\config.gypi
gyp verb config.gypi checking for gypi file: C:\cpp\screenshot\config.gypi
gyp verb common.gypi checking for gypi file: C:\cpp\screenshot\common.gypi
gyp verb gyp gyp format was not specified; forcing "msvs"
gyp info spawn C:\Python39\python.exe
gyp info spawn args [
gyp info spawn args 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'msvs',
gyp info spawn args '-I',
gyp info spawn args 'C:\\cpp\\screenshot\\build\\config.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args '-I',
gyp info spawn args 'C:\\Users\\User\\AppData\\Local\\node-gyp\\Cache\\13.7.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=C:\\Users\\User\\AppData\\Local\\node-gyp\\Cache\\13.7.0',
gyp info spawn args '-Dnode_gyp_dir=C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp',
gyp info spawn args '-Dnode_lib_file=C:\\\\Users\\\\User\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\13.7.0\\\\<(target_arch)\\\\node.lib',
gyp info spawn args '-Dmodule_root_dir=C:\\cpp\\screenshot',
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 'C:\\cpp\\screenshot\\build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
Traceback (most recent call last):
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\gyp_main.py", line 51, in <module>
sys.exit(gyp.script_main())
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 687, in script_main
return main(sys.argv[1:])
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 679, in main
return gyp_main(args)
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 645, in gyp_main
[generator, flat_list, targets, data] = Load(
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 151, in Load
result = gyp.input.Load(
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 3052, in Load
LoadTargetBuildFile(
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 411, in LoadTargetBuildFile
build_file_data = LoadOneBuildFile(
File "C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 239, in LoadOneBuildFile
build_file_contents = open(build_file_path, "rU").read()
ValueError: invalid mode: 'rU' 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 (C:\Users\User\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:351:16)
gyp ERR! stack at ChildProcess.emit (events.js:321:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\User\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure" "--verbose"
gyp ERR! cwd C:\cpp\screenshot
gyp ERR! node -v v13.7.0
gyp ERR! node-gyp -v v7.1.0
gyp ERR! not ok
I know that Python 3.9 isn’t mentioned on the supported releases and don’t ask me why I had it installed in the first place, but I just thought I’d report this since I didn’t see it mentioned elsewhere, it looks like the “U” flag when opening a file has been deprecated, this causes the “node-gyp configure” command to fail with the above output. In “input.py” I removed the “U” from the offending function call and it worked fine after that. Please let me know if this has already been discussed.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Node gyp ERR - invalid mode: 'rU' while trying to load binding ...
I was having this issue ValueError: invalid mode: 'rU' while trying to load binding.gyp when using npm install. Valentinos answer helped me, ...
Read more >python is not set from command line or npm configuration gyp ...
Electron uses node-gyp for build itself, that needs to install python and ... ValueError: invalid mode: 'rU' while trying to load binding.gyp gyp...
Read more >A Comprehensive Guide to Fixing Node-Gyp Issues on Windows
1. Try running npm install with the --no-optional flag. · 2. Try downloading the windows-build-tools package. · 3. Download the Visual Studio 2015 ......
Read more >Source - GitHub
... Bug Fixes * lock windows env ([#163](https://github.com/nodejs/gyp-next/issues/163)) ... ValueError: invalid mode: 'rU' while trying to load binding.gyp ...
Read more >SUSE-IU-2022:237-1: Security update of suse-sles-15-chost ...
CVE-2020-11668: Fixed the mishandling of invalid descriptors in the ... following issues: - Restored compatibility with Python 2.7 update ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m seeing this on Windows 11 with Python 3.9 or 3.11. How can we fix it? It seems like it should not occur after the fix of this PR, but it is.
I can confirm that downgrading python in my conda environment from 3.11.1 to 3.10.8 fixed this problem for me.