如何修复 Python pip install openai 错误:subprocess-exited-with-error

Ljy*_*eon 4 python windows python-3.x openai-api gpt-3

我正在尝试使用 Python 3.11、Windows 操作系统、pip 完全升级来安装 OpenAI,但出现此错误。

\n

这是完整的错误消息:

\n
Collecting openai\n  Using cached openai-0.26.0.tar.gz (54 kB)\n  Installing build dependencies ... done\n  Getting requirements to build wheel ... error\n  error: subprocess-exited-with-error\n\n  \xc3\x97 Getting requirements to build wheel did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [21 lines of output]\n      Traceback (most recent call last):\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 351, in <module>\n          main()\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 333, in main\n          json_out[\'return_val\'] = hook(**hook_input[\'kwargs\'])\n                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n        File "C:\\Users\\vocal\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\pip\\_vendor\\pep517\\in_process\\_in_process.py", line 118, in get_requires_for_build_wheel\n          return hook(config_settings)\n                 ^^^^^^^^^^^^^^^^^^^^^\n        File "C:\\Users\\vocal\\AppData\\Local\\Temp\\pip-build-env-lr3fjsgg\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 338, in get_requires_for_build_wheel\n          return self._get_build_requires(config_settings, requirements=[\'wheel\'])\n                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n        File "C:\\Users\\vocal\\AppData\\Local\\Temp\\pip-build-env-lr3fjsgg\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 320, in _get_build_requires\n          self.run_setup()\n        File "C:\\Users\\vocal\\AppData\\Local\\Temp\\pip-build-env-lr3fjsgg\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 485, in run_setup\n          self).run_setup(setup_script=setup_script)\n                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n        File "C:\\Users\\vocal\\AppData\\Local\\Temp\\pip-build-env-lr3fjsgg\\overlay\\Lib\\site-packages\\setuptools\\build_meta.py", line 335, in run_setup\n          exec(code, locals())\n        File "<string>", line 13, in <module>\n      UnicodeDecodeError: \'cp949\' codec can\'t decode byte 0xe2 in position 1031: illegal multibyte sequence\n      [end of output]\n\n  note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: subprocess-exited-with-error\n\n\xc3\x97 Getting requirements to build wheel did not run successfully.\n\xe2\x94\x82 exit code: 1\n\xe2\x95\xb0\xe2\x94\x80> See above for output.\n\nnote: This error originates from a subprocess, and is likely not a problem with pip.\n\n
Run Code Online (Sandbox Code Playgroud)\n

我不知道如何解决这个错误。有人能给我提示吗?

\n
UnicodeDecodeError: \'cp949\' codec can\'t decode byte 0xe2 in position 1031: illegal multibyte sequence\n
Run Code Online (Sandbox Code Playgroud)\n

由于该消息,我尝试了这个解决方案,但它不起作用。

\n

小智 7

我在 Google Colab 工作,也遇到了同样的问题。我通过做同样的事情修复了它。

!pip install --upgrade pip
!pip install openai
Run Code Online (Sandbox Code Playgroud)


小智 6

我最近在一个新的 Linux 虚拟机上遇到了这个问题,但解决方案实际上非常简单。我将 pip 版本添加到安装命令中,例如pip3.10 install openai,一切都按预期工作。

对于您的 Windows 环境来说,这可能不是同一个问题,但这是我发布的完整文章,因为当时我找不到任何有用的信息。