1.背景
安装psycopg2-binary,安装命令“pip install psycopg2-binary==2.9.7”
完整报错信息如下:
(venv) PS D:\workspace_all\pyCharm\MaxKB-main> pip install psycopg2-binary==2.9.7
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting psycopg2-binary==2.9.7
Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/45/f4/4da1e7f836de4fa3ddb294bb1d4c08daa5cd7b261a6b9a5b50a653a1a29f/psycopg2-binary-2.
9.7.tar.gz (383 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [51 lines of output]
running egg_info
creating C:\Users\PC2023\AppData\Local\Temp\pip-pip-egg-info-ss06iuch\psycopg2_binary.egg-info
writing C:\Users\PC2023\AppData\Local\Temp\pip-pip-egg-info-ss06iuch\psycopg2_binary.egg-info\PKG-INFO
writing dependency_links to C:\Users\PC2023\AppData\Local\Temp\pip-pip-egg-info-ss06iuch\psycopg2_binary.egg-info\dependency_links.txt
writing top-level names to C:\Users\PC2023\AppData\Local\Temp\pip-pip-egg-info-ss06iuch\psycopg2_binary.egg-info\top_level.txt
writing manifest file 'C:\Users\PC2023\AppData\Local\Temp\pip-pip-egg-info-ss06iuch\psycopg2_binary.egg-info\SOURCES.txt'
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "C:\Users\PC2023\AppData\Local\Temp\pip-install-bm4e40p_\psycopg2-binary_db67a293b0e046a98ffade0b41601821\setup.py", line 551, in <mo
dule>
setup(name="psycopg2-binary",
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\__init__.py", line 108, in setup
return distutils.core.setup(**attrs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\core.py", line 184, in setup
return run_commands(dist)
^^^^^^^^^^^^^^^^^^
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\core.py", line 200, in run_commands
dist.run_commands()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\dist.py", line 970, in run_commands
self.run_command(cmd)
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\dist.py", line 945, in run_command
super().run_command(command)
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\dist.py", line 989, in run_command
cmd_obj.run()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\command\egg_info.py", line 310, in run
self.find_sources()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\command\egg_info.py", line 318, in find_sources
mm.run()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\command\egg_info.py", line 539, in run
self.add_defaults()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\command\egg_info.py", line 577, in add_defaults
sdist.add_defaults(self)
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\command\sdist.py", line 102, in add_defaults
super().add_defaults()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 250, in add_defaults
self._add_defaults_ext()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\command\sdist.py", line 334, in _add_defaults_ext
build_ext = self.get_finalized_command('build_ext')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\cmd.py", line 303, in get_finalized_command
cmd_obj.ensure_finalized()
File "D:\workspace_all\pyCharm\MaxKB-main\venv\Lib\site-packages\setuptools\_distutils\cmd.py", line 111, in ensure_finalized
self.finalize_options()
File "C:\Users\PC2023\AppData\Local\Temp\pip-install-bm4e40p_\psycopg2-binary_db67a293b0e046a98ffade0b41601821\setup.py", line 381, in fin
alize_options
tokens = pg_config_helper.query("ldflags", empty_ok=True).split()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\PC2023\AppData\Local\Temp\pip-install-bm4e40p_\psycopg2-binary_db67a293b0e046a98ffade0b41601821\setup.py", line 122, in que
ry
result = pg_config_process.stdout.decode().strip()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 2: invalid continuation byte
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
[notice] A new release of pip is available: 23.2.1 -> 24.2
[notice] To update, run: python.exe -m pip install --upgrade pip
2.问题分析
这种问题是因为编码问题导致的。
找到错误日志中报错位置,修改编码即可。
3.解决方案
由于在线安装无法修改代码,所有需要先把对应的插件下载下来,然后修改代码。
3.1 下载插件
根据错误日志,找到需要下载的插件:
3.2 解压
3.3 修改代码
根据错误日志,找到出错位置:
修改代码:
3.4 离线安装
3.5 搞定
pip list: