构建 pypiwin32 失败

Failed to build pypiwin32

好吧,过去一个小时我一直在尝试安装 pywintypes 库,并搜索到它是 pypiwin32,但它不起作用,无法构建另外尝试通过下载源代码手动安装它和 运行 setup.py 但得到了同样的错误:我得到这个错误并且我有 python 3.10

Collecting pypiwin32
  Using cached pypiwin32-223-py3-none-any.whl (1.7 kB)
  Using cached pypiwin32-219.zip (4.8 MB)
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\Rasmus\AppData\Local\Programs\Python\Python310\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\Rasmus\AppData\Local\Temp\pip-install-3z4zmi2y\pypiwin32_ec886c51d7334f269d55dee9cd57e04b\setup.py'"'"'; __file__='"'"'C:\Users\Rasmus\AppData\Local\Temp\pip-install-3z4zmi2y\pypiwin32_ec886c51d7334f269d55dee9cd57e04b\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'"'"'))' egg_info --egg-base 'C:\Users\Rasmus\AppData\Local\Temp\pip-pip-egg-info-6dg0frr7'
         cwd: C:\Users\Rasmus\AppData\Local\Temp\pip-install-3z4zmi2y\pypiwin32_ec886c51d7334f269d55dee9cd57e04b\
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\Rasmus\AppData\Local\Temp\pip-install-3z4zmi2y\pypiwin32_ec886c51d7334f269d55dee9cd57e04b\setup.py", line 121
        print "Building pywin32", pywin32_version
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/2b/ca/5c086c18de8f70222787b3e824e755b68d99272531522e77bb381d4f60c8/pypiwin32-219.zip#sha256=06d478295c89dbdd4187e1ac099bb8eab93c29e298bded4e2fbc77009287fa44 (from https://pypi.org/simple/pypiwin32/). Command errored out with exit status 1:
python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement pywin32>=223 (from pypiwin32) (from versions: none)
ERROR: No matching distribution found for pywin32>=223

我能看到的唯一解决方案是从 python 3.10 降级到 3.9

pywin32 版本 302(不是 pypiwin32,看起来像是 2018 年的错误)已于 2021 年 10 月 10 日上传到 PyPi,并在更改日志中声明:

  • Support for Python 10, dropped support for Python 3.5 (3.5 security support ended 13 Sep 2020)

演示(使用 PyLauncher 更新我的 3.10 安装):

C:\>py -3.10 -m pip install pywin32
Collecting pywin32
  Downloading pywin32-302-cp310-cp310-win_amd64.whl (9.2 MB)
     |████████████████████████████████| 9.2 MB 6.8 MB/s
Installing collected packages: pywin32
Successfully installed pywin32-302

确保从管理员命令提示符 运行 Scripts\pywin32_postinstall.py 并正确注册。确保它也在 3.10 安装的上下文中 运行s(再次使用 PyLauncher):

C:\Python310\Scripts>py -3.10 pywin32_postinstall.py -install
Parsed arguments are: Namespace(install=True, remove=False, wait=None, silent=False, quiet=False, destination='C:\Python310\Lib\site-packages')
Copied pythoncom310.dll to C:\windows\system32\pythoncom310.dll
Copied pywintypes310.dll to C:\windows\system32\pywintypes310.dll
Registered: Python.Interpreter
Registered: Python.Dictionary
Registered: Python
-> Software\Python\PythonCore.10\Help[None]=None
-> Software\Python\PythonCore.10\Help\Pythonwin Reference[None]='C:\Python310\Lib\site-packages\PyWin32.chm'
Registered help file
Pythonwin has been registered in context menu
Shortcut for Pythonwin created
Shortcut to documentation created
The pywin32 extensions were successfully installed.