pip install pythonnet 在 Windows 10 (Python 3.10.1) 上出错,退出状态为 1

pip install pythonnet errored out with exit status 1 on Windows 10 (Python 3.10.1)

根据官方 Python.NET 文档,我应该使用 pip install pythonnet 安装它,但是这给了我一个错误。我已经升级了以下软件包试图修复它:

但这并没有解决它,它抛出了一些错误。

Collecting pythonnet
  Using cached pythonnet-2.5.2.tar.gz (1.9 MB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: pycparser in c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages (from pythonnet) (2.21)
Building wheels for collected packages: pythonnet
  Building wheel for pythonnet (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\users\kiron\appdata\local\programs\python\python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"'; __file__='"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\kiron\AppData\Local\Temp\pip-wheel-teu689ee'
       cwd: C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\
  Complete output (91 lines):
  running bdist_wheel
  running build
  running build_ext
  Checking for updates from https://www.nuget.org/api/v2/.
  Currently running NuGet.exe 4.1.0.
  Updating NuGet.exe to 6.0.0.
  Update successful.
  Cannot find the specified version of msbuild: '14'
  MSBuild auto-detection: using msbuild version '16.11.2.50704' from 'C:\Program Files (x86)\Microsoft Visual Studio19\Community\MSBuild\Current\bin'.
  Restoring NuGet package NUnit.ConsoleRunner.3.11.1.
  Restoring NuGet package NUnit.3.12.0.
  Adding package 'NUnit.3.12.0' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Adding package 'NUnit.ConsoleRunner.3.11.1' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Added package 'NUnit.ConsoleRunner.3.11.1' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Restoring NuGet package System.ValueTuple.4.5.0.
  Adding package 'System.ValueTuple.4.5.0' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Added package 'NUnit.3.12.0' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Restoring NuGet package UnmanagedExports.1.2.7.
  Adding package 'UnmanagedExports.1.2.7' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Added package 'System.ValueTuple.4.5.0' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'
  Added package 'UnmanagedExports.1.2.7' to folder 'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\packages'

  NuGet Config files used:
      C:\Users\kiron\AppData\Roaming\NuGet\NuGet.Config
      C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config

  Feeds used:
      C:\Users\kiron\.nuget\packages\
      https://api.nuget.org/v3/index.json
      https://packages.stride3d.net/nuget
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\

  Installed:
      4 package(s) to packages.config projects
  Traceback (most recent call last):
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\tools\geninterop\geninterop.py", line 396, in <module>
      sys.exit(main())
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\tools\geninterop\geninterop.py", line 357, in main
      python_h = preprocess_python_headers()
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\tools\geninterop\geninterop.py", line 238, in preprocess_python_headers
      for line in _check_output(cmd).splitlines():
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\tools\geninterop\geninterop.py", line 46, in _check_output
      output = subprocess.check_output(*args, **kwargs)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\subprocess.py", line 420, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\subprocess.py", line 501, in run
      with Popen(*popenargs, **kwargs) as process:
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\subprocess.py", line 966, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\subprocess.py", line 1435, in _execute_child
      hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  FileNotFoundError: [WinError 2] The system cannot find the file specified
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py", line 630, in <module>
      setup(
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\__init__.py", line 155, in setup
      return distutils.core.setup(**attrs)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\core.py", line 148, in setup
      return run_commands(dist)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\core.py", line 163, in run_commands
      dist.run_commands()
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\dist.py", line 967, in run_commands
      self.run_command(cmd)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py", line 612, in run
      return bdist_wheel.bdist_wheel.run(self)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\wheel\bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\dist.py", line 986, in run_command
      cmd_obj.run()
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 339, in run
      self.build_extensions()
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 448, in build_extensions
      self._build_extensions_serial()
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 473, in _build_extensions_serial
      self.build_extension(ext)
    File "C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py", line 302, in build_extension
      subprocess.check_call([sys.executable, geninterop, interop_file])
    File "c:\users\kiron\appdata\local\programs\python\python310\lib\subprocess.py", line 369, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['c:\users\kiron\appdata\local\programs\python\python310\python.exe', 'tools\geninterop\geninterop.py', 'src\runtime\interop310.cs']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for pythonnet
  Running setup.py clean for pythonnet
Failed to build pythonnet
Installing collected packages: pythonnet
    Running setup.py install for pythonnet ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\kiron\appdata\local\programs\python\python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"'; __file__='"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\kiron\AppData\Local\Temp\pip-record-xe4ba95q\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\kiron\appdata\local\programs\python\python310\Include\pythonnet'
         cwd: C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\
    Complete output (6 lines):
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: setup.py --help [cmd1 cmd2 ...]
       or: setup.py --help-commands
       or: setup.py cmd --help

    error: option --single-version-externally-managed not recognized
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\kiron\appdata\local\programs\python\python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"'; __file__='"'"'C:\Users\kiron\AppData\Local\Temp\pip-install-aqpb12ju\pythonnet_af0b8f5732a345fbb5e2d512446e9f59\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\kiron\AppData\Local\Temp\pip-record-xe4ba95q\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\kiron\appdata\local\programs\python\python310\Include\pythonnet' Check the logs for full command output.

现在,我确实看到它与我的 VS2019 安装有关,但我无法确定是什么问题。我应该重新安装 VS2019 吗?如果是这样,我应该安装哪些工作负载和单个组件?

编辑 1

我刚刚重新安装了 VS2019,具有以下工作负载、它们的安装详细信息以及以下各个组件:

我在 pip 中仍然遇到同样的错误。

Python.NET 2.5.2 仅支持 Python 3.8 或更早版本。如果需要 运行 和 3.10.

,您可能想尝试 3.0.0 预览版