在windows 10中编写pip install psycopg2以将python与我的Django项目的postgres连接时出错

2024-05-06 21:10:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为Django项目安装psycopg2以连接Postgres,但出现以下错误:

当我运行此命令时:

pip install psycopg2

在Windows上,我遇到以下错误:

C:\Users\Aman>pip install psycopg2 Collecting psycopg2 Using cached psycopg2-2.8.5.tar.gz (380 kB) Using legacy setup.py install for psycopg2, since package 'wheel' is not installed. Installing collected packages: psycopg2 Running setup.py install for psycopg2 ... error ERROR: Command errored out with exit status 1: command: 'c:\users\aman\appdata\local\programs\python\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Aman\\AppData\\Local\\Temp\\pip-install-8u0ripm3\\psycopg2\\setup.py'"'"'; __file__='"'"'C:\\Users\\Aman\\AppData\\Local\\Temp\\pip-install-8u0ripm3\\psycopg2\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Aman\AppData\Local\Temp\pip-record-dasbftyv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\aman\appdata\local\programs\python\python39\Include\psycopg2' cwd: C:\Users\Aman\AppData\Local\Temp\pip-install-8u0ripm3\psycopg2\ Complete output (22 lines): running install running build running build_py creating build creating build\lib.win-amd64-3.9 creating build\lib.win-amd64-3.9\psycopg2 copying lib\compat.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\errorcodes.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\errors.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\extensions.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\extras.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\pool.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\sql.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\tz.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\_ipaddress.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\_json.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\_lru_cache.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\_range.py -> build\lib.win-amd64-3.9\psycopg2 copying lib\__init__.py -> build\lib.win-amd64-3.9\psycopg2 running build_ext building 'psycopg2._psycopg' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ ---------------------------------------- ERROR: Command errored out with exit status 1: 'c:\users\aman\appdata\local\programs\python\python39\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Aman\\AppData\\Local\\Temp\\pip-install-8u0ripm3\\psycopg2\\setup.py'"'"'; __file__='"'"'C:\\Users\\Aman\\AppData\\Local\\Temp\\pip-install-8u0ripm3\\psycopg2\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Aman\AppData\Local\Temp\pip-record-dasbftyv\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\aman\appdata\local\programs\python\python39\Include\psycopg2' Check the logs for full command output.

如何修复此错误


Tags: installpippybuildliblocalsetupwin
1条回答
网友
1楼 · 发布于 2024-05-06 21:10:26

错误显示:

Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ 

安装此“VisualStudio构建工具”,可能是通过以下链接进行的。 https://visualstudio.microsoft.com/downloads/

相关问题 更多 >