我无法在python中安装pywin32或pypiwin32

问题描述 投票:0回答:1

当我尝试执行

pip3 install pypiwin32
时,我收到如下错误:

Collecting pypiwin32
  Using cached pypiwin32-223-py3-none-any.whl (1.7 kB)
INFO: pip is looking at multiple versions of pypiwin32 to determine which version is compatible with other requirements. This could take a while.
  Using cached pypiwin32-219.zip (4.8 MB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      Traceback (most recent call last):
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/np/j0b1hzy156ncglb74zdj8hcw0000gn/T/pip-build-env-11jntcle/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/np/j0b1hzy156ncglb74zdj8hcw0000gn/T/pip-build-env-11jntcle/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/np/j0b1hzy156ncglb74zdj8hcw0000gn/T/pip-build-env-11jntcle/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/private/var/folders/np/j0b1hzy156ncglb74zdj8hcw0000gn/T/pip-build-env-11jntcle/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 121
          print "Building pywin32", pywin32_version
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
python
1个回答
-2
投票

根据错误消息中的文件路径,您似乎正在尝试在 Linux 系统上安装

pywin32
,这就是它失败的原因。

pywin32
仅适用于 Windows 系统,因为它依赖于 Windows DLL。您需要在 Windows 计算机上使用
pywin32
软件包。

错误信息具体原因:

语法错误:调用“打印”时缺少括号。您的意思是 print(...) 吗? [输出结束]

是因为在 Linux 上,pip 找不到当前版本,并尝试安装旧的缓存版本(2018 年 2 月的版本 223),这是该包的 Python 2.7 版本。在 Python 2 中,

print
是关键字而不是函数,因此
print "Building pywin32"
是有效的 Python2 代码,但在 Python3 中会崩溃。

我只能假设该版本在某个时候被标记为适用于 Linux,但我不知道这是有意还是无意。

© www.soinside.com 2019 - 2024. All rights reserved.