Skip to content

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

Closed
nodejs/gyp-next
#83

Description

@BriceKrispies
  • 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.

Activity

  1. cclauss commented on Sep 12, 2020

    @cclauss
    Contributor

    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.

  2. richardlau commented on Sep 12, 2020

    @richardlau
    Member
  3. added a commit that references this issue on Nov 26, 2020
    3f8cb33
  4. added a commit that references this issue on Nov 27, 2020
    d0504e6
  5. Nantris commented on Nov 30, 2022

    @Nantris

    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.

  6. reuben commented on Dec 17, 2022

    @reuben

    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.

  7. reuben commented on Dec 17, 2022

    @reuben

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

  8. cclauss commented on Dec 17, 2022

    @cclauss
    Contributor

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

  9. cst-ramirez commented on Dec 20, 2022

    @cst-ramirez

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

  10. reuben commented on Dec 20, 2022

    @reuben

    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

  11. fahnub commented on Jan 10, 2023

    @fahnub

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

  12. clarabez commented on Jan 27, 2023

    @clarabez

    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()))
    
  13. locked as resolved and limited conversation to collaborators on Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions