虚拟环境中安装flask-scaffold时psycopg2-2.6下载失败求助
安装flask-scaffold时psycopg2-2.6安装失败的解决办法
执行pip install flask-scaffold时,因无法安装psycopg2-2.6导致失败,当前使用virtualenv虚拟环境,具体报错信息如下:
Collecting psycopg2==2.6 Using cached psycopg2-2.6.tar.gz (367 kB) ERROR: Command errored out with exit status 1: command: 'd:\python\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\86131\AppData\Local\Temp\pip-install-kwovtp7e\psycopg2\setup.py'"'"'; __file__='"'"'C:\Users\86131\AppData\Local\Temp\pip-install-kwovtp7e\psycopg2\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4' cwd: C:\Users\86131\AppData\Local\Temp\pip-install-kwovtp7e\psycopg2\ Complete output (14 lines): running egg_info creating C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4\psycopg2.egg-info writing C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4\psycopg2.egg-info\PKG-INFO writing dependency_links to C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4\psycopg2.egg-info\dependency_links.txt writing top-level names to C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4\psycopg2.egg-info\top_level.txt writing manifest file 'C:\Users\86131\AppData\Local\Temp\pip-pip-egg-info-8deozwr4\psycopg2.egg-info\SOURCES.txt' Error: pg_config executable not found. Please add the directory containing pg_config to the PATH or specify the full executable path with the option: python setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup.cfg'. ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
报错核心为:未找到pg_config可执行文件,以下是几种解决办法:
使用预编译的psycopg2-binary替代
这是最简单的方案,psycopg2-binary是预编译版本,无需编译环境和pg_config。先执行:pip install psycopg2-binary==2.6安装完成后再执行
pip install flask-scaffold即可。安装PostgreSQL并配置PATH
下载安装对应版本的PostgreSQL,安装完成后将PostgreSQL安装目录下的bin文件夹(比如C:\Program Files\PostgreSQL\14\bin)添加到系统环境变量PATH中,重启终端后重新执行pip install flask-scaffold。手动指定pg_config路径
如果已经安装了PostgreSQL,找到pg_config的完整路径(比如C:\Program Files\PostgreSQL\14\bin\pg_config.exe),执行以下命令安装psycopg2:pip install psycopg2==2.6 --global-option=build_ext --global-option="--pg-config=C:\Program Files\PostgreSQL\14\bin\pg_config.exe"安装成功后再安装flask-scaffold。
内容的提问来源于stack exchange,提问作者Emroy
相关产品推荐
相关产品推荐

