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

ValueError: invalid mode: 'rU' while trying to load binding.gyp (Python 3.9 compatibility issue) #2219

Closed
Brice1994 opened this issue Sep 12, 2020 · 10 comments · Fixed by nodejs/gyp-next#83

Comments

@Brice1994
Copy link

  • 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 [email protected]
gyp info using [email protected] | 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.

@cclauss
Copy link
Contributor

cclauss commented Sep 12, 2020

Please submit a pull request... I think this change would be valuable to Python users.

Python 3.9 general release is scheduled for Oct. 5th.

@richardlau
Copy link
Member

Please submit any pull requests to https://github.com/nodejs/gyp-next.

ogoffart referenced this issue in slint-ui/slint Nov 2, 2022
Python recently was updated to 3.11 and the build of the node binding is
now failing.
(Apparently still using a quite old version of node-gyp, because this
was fixed in `https://github.com/nodejs/node-gyp/issues/2219`)

```
     File "/home/runner/work/slint/slint/target/debug/build/neon-sys-4b140f4af6e7aeb3/out/native/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
```
ogoffart referenced this issue in slint-ui/slint Nov 2, 2022
Python recently was updated to 3.11 and the build of the node binding is
now failing.
(Apparently still using a quite old version of node-gyp, because this
was fixed in `https://github.com/nodejs/node-gyp/issues/2219`)

```
     File "/home/runner/work/slint/slint/target/debug/build/neon-sys-4b140f4af6e7aeb3/out/native/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
```
@Nantris
Copy link

Nantris commented Nov 30, 2022

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.

@reuben
Copy link

reuben commented Dec 17, 2022

Looks like the vendored copy of gyp here needs to be updated to gyp-next 0.6.3, and then a new node-gyp release has to be made, and then dependencies have to be updated.

@reuben
Copy link

reuben commented Dec 17, 2022

Actually, vendored gyp is already updated, so maybe just updating node-gyp is enough.

@cclauss
Copy link
Contributor

cclauss commented Dec 17, 2022

The U file mode was removed in Python 3.11 because it had no effect so the U can merely be removed.

@cst-ramirez
Copy link

I can confirm that downgrading python in my conda environment from 3.11.1 to 3.10.8 fixed this problem for me.

@reuben
Copy link

reuben commented Dec 20, 2022

The U file mode was removed in Python 3.11 because it had no effect so the U can merely be removed.

It's already been fixed by nodejs/gyp-next@d0504e6

@fahnub
Copy link

fahnub commented Jan 10, 2023

Using Python3.11 and removing the "U" from the function in input.py resolved it for me.

emcniece pushed a commit to cncjs/cncjs that referenced this issue Jan 16, 2023
…#796)

* html5-webcam: feat: Update Webcam widget to allow streaming h264(mp4) remote streams

* html5-webcam: chore: Bump appveyor nodejs to v14

* html5-webcam: chore: npm@latest on node 14 is broken on Windows

* html5-webcam: chore: fix broken node-gyp build on Python 3.11 nodejs/node-gyp#2219

* html5-webcam: chore: attempt to fix broken node-gyp again

* html5-webcam: html5-webcam: chore: Escape backslashes in PATH, set PATHoutside PS
@clarabez
Copy link

I had the same problem with Python3.11, updating input.py as @fahnub mentioned, worked to me:
/Users/username/npm-versions/6.13.7/node_modules/node-gyp/gyp/pylib/gyp/input.py

Check the comment for the first else:

def LoadOneBuildFile(build_file_path, data, aux_data, includes,
                     is_target, check):
  if build_file_path in data:
    return data[build_file_path]

  if os.path.exists(build_file_path):
    # Open the build file for read ('r') with universal-newlines mode ('U')
    # to make sure platform specific newlines ('\r\n' or '\r') are converted to '\n'
    # which otherwise will fail eval()
    if sys.platform == 'zos':
      # On z/OS, universal-newlines mode treats the file as an ascii file. But since
      # node-gyp produces ebcdic files, do not use that mode.
      build_file_contents = open(build_file_path, 'r').read()
    else:
      build_file_contents = open(build_file_path, 'r').read() # Here is the line you need to update. Instead of 'rU', update to only 'r'
  else:
    raise GypError("%s not found (cwd: %s)" % (build_file_path, os.getcwd()))

@nodejs nodejs locked as resolved and limited conversation to collaborators Jan 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants