1

I try to install pythonnet and got an errer, how can I fix that??

p.s the Microsoft.CSharp.Core.targets does not exist from the beginning

so I copy form "https://referencesource.microsoft.com/#MSBuildFiles/C/ProgramFiles(x86)/MSBuild/14.0/bin_/amd64/Microsoft.CSharp.Core.targets,4b2d25f00a74b6f8" myself.

error:

  ERROR: Command errored out with exit status 1:
   command: 'c:\users\User\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"'; __file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\User\AppData\Local\Temp\pip-wheel-7jl8gkpe'
       cwd: C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\
  Complete output (83 lines):
  running bdist_wheel
  running build
  running build_ext
  ?????? https://www.nuget.org/api/v2/ ????
  ?????? NuGet.exe 4.1.0?
  ???? NuGet.exe ? 5.4.0?
  ?????
  Cannot find the specified version of msbuild: '14'
  MSBuild auto-detection: using msbuild version '16.0.462.64354' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin'.
  Restoring NuGet package NUnit.3.7.1.
  Restoring NuGet package NUnit.ConsoleRunner.3.7.0.
  Restoring NuGet package UnmanagedExports.1.2.7.
  Adding package 'NUnit.3.7.1' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'
  Adding package 'NUnit.ConsoleRunner.3.7.0' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'
  Adding package 'UnmanagedExports.1.2.7' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'
  Added package 'UnmanagedExports.1.2.7' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'
  Added package 'NUnit.ConsoleRunner.3.7.0' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'
  Added package 'NUnit.3.7.1' to folder 'C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\packages'

  NuGet Config files used:
      C:\Users\User\AppData\Roaming\NuGet\NuGet.Config

  Feeds used:
      C:\Users\User\.nuget\packages\
      https://api.nuget.org/v3/index.json

  Installed:
      3 package(s) to packages.config projects
  Traceback (most recent call last):
    File "tools\geninterop\geninterop.py", line 293, in <module>
      sys.exit(main())
    File "tools\geninterop\geninterop.py", line 273, in main
      python_h = preprocess_python_headers()
    File "tools\geninterop\geninterop.py", line 193, in preprocess_python_headers
      for line in _check_output(cmd).splitlines():
    File "tools\geninterop\geninterop.py", line 41, in _check_output      
      output = subprocess.check_output(*args, **kwargs)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\subprocess.py", line 411, in check_output
      return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,    
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\subprocess.py", line 489, in run
      with Popen(*popenargs, **kwargs) as process:
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\subprocess.py", line 854, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,        
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\subprocess.py", line 1307, in _execute_child
      hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  FileNotFoundError: [WinError 2] \u7cfb\u7d71\u627e\u4e0d\u5230\u6307\u5b9a\u7684\u6a94\u6848\u3002
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\setup.py", line 623, in <module>
      setup(
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\site-packages\setuptools\__init__.py", line 144, in setup
      return distutils.core.setup(**attrs)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\setup.py", line 610, in run
      return bdist_wheel.bdist_wheel.run(self)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\site-packages\wheel\bdist_wheel.py", line 223, in run
      self.run_command('build')
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\command\build_ext.py", line 340, in run
      self.build_extensions()
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\command\build_ext.py", line 449, in build_extensions
      self._build_extensions_serial()
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\distutils\command\build_ext.py", line 474, in _build_extensions_serial    
      self.build_extension(ext)
    File "C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\setup.py", line 298, in build_extension
      subprocess.check_call([sys.executable, geninterop, interop_file])   
    File "c:\users\User\appdata\local\programs\python\python38-32\lib\subprocess.py", line 364, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['c:\\users\\User\\appdata\\local\\programs\\python\\python38-32\\python.exe', 'tools\\geninterop\\geninterop.py', 'src\\runtime\\interop38.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\User\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"'; __file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-0d2o62h0\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\User\appdata\local\programs\python\python38-32\Include\pythonnet'
         cwd: C:\Users\User\AppData\Local\Temp\pip-install-93okize6\pythonnet\
    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\User\appdata\local\programs\python\python38-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"'; __file__='"'"'C:\\Users\\User\\AppData\\Local\\Temp\\pip-install-93okize6\\pythonnet\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, 
'"'"'exec'"'"'))' install --record 'C:\Users\User\AppData\Local\Temp\pip-record-0d2o62h0\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\User\appdata\local\programs\python\python38-32\Include\pythonnet' Check the logs for full command output.
AMC
  • 2,642
  • 7
  • 13
  • 35
pynew
  • 21
  • 1
  • 7
  • Does this answer your question? [What does "error: option --single-version-externally-managed not recognized" indicate?](https://stackoverflow.com/questions/14296531/what-does-error-option-single-version-externally-managed-not-recognized-ind) – AMC Feb 13 '20 at 03:54
  • @AMC My setuptools and wheel is up to date... – pynew Feb 13 '20 at 04:17
  • Did you check some of the other suggestions in that question? – AMC Feb 13 '20 at 17:21
  • @AMC install distribute ? another error come up... AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader' – pynew Feb 14 '20 at 14:19
  • This might be useful: https://stackoverflow.com/questions/44761958/using-pip3-module-importlib-bootstrap-has-no-attribute-sourcefileloader – AMC Mar 02 '20 at 20:20

1 Answers1

0

I had this problem too. I was using the newest python to date, v3.9.5. From reading the Pyton.NET docs @ http://pythonnet.github.io/, I found that "Python.NET is currently compatible and tested with Python releases 2.7 and 3.5-3.8". I downloaded and installed the latest 3.8 version of Python for Windows (3.8.10 to date). I updated my path to use Python 3.8 (@ C:\Users\user\AppData\Local\Programs\Python\Python38 on my computer). After that I was able to install Python.NET from cmd with:

python -m pip install pythonnet
Samuel
  • 8,063
  • 8
  • 45
  • 41