如何修复pythonnet安装过程中的错误

问题描述

当我尝试使用以下命令时:

pip install pythonnet

我看到您可以在下面看到的错误

Collecting pythonnet
  Using cached pythonnet-2.5.2.tar.gz (1.9 MB)
Requirement already satisfied: pycparser in c:\users\d4wt0\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages (from pythonnet) (2.20)
Using legacy 'setup.py install' for pythonnet,since package 'wheel' is not installed.
Installing collected packages: pythonnet
    Running setup.py install for pythonnet ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\d4wt0\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io,os,sys,setuptools,tokenize; sys.argv[0] = '"'"'C:\\Users\\d4wt0\\AppData\\Local\\Temp\\pip-install-jlv07504\\pythonnet_0928bad80975481c9950abc5017a28b4\\setup.py'"'"'; __file__='"'"'C:\\Users\\d4wt0\\AppData\\Local\\Temp\\pip-install-jlv07504\\pythonnet_0928bad80975481c9950abc5017a28b4\\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\d4wt0\AppData\Local\Temp\pip-record-x2n0fvt3\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\d4wt0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\python39\Include\pythonnet'
         cwd: C:\Users\d4wt0\AppData\Local\Temp\pip-install-jlv07504\pythonnet_0928bad80975481c9950abc5017a28b4\
    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\d4wt0\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe' -u -c 'import io,'"'"'exec'"'"'))' install --record 'C:\Users\d4wt0\AppData\Local\Temp\pip-record-x2n0fvt3\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\d4wt0\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\python39\Include\pythonnet' Check the logs for full command output.

我该如何解决?我尝试使用 PyCharm 安装该软件包,但出现相同的错误。有什么想法吗?

解决方法

docs 我可以看到它不支持 python 3.9 所以你可以从 here

由于您的 python 版本是 3.9,因此请根据您的系统 32 位或 64 位 python 版本下载 pythonnet‑2.5.2‑cp39‑cp39‑win_amd64.whl

并提供安装为 pip install wheel-file

的完整路径