随笔 - 3  文章 - 2  评论 - 0  阅读 - 2306

pip安装依赖psycopg2

说明

在学习Fastapi的过程中链接, 使用psycopg2库连接postgresql数据库。
在执行pip install psycopg2时,报错:

(venv)  ✘  ~/Documents/workspace/learning_fastapi   master ±  
(venv)  ✘  ~/Documents/workspace/learning_fastapi   master ±  pip3 install psycopg2-binary               
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting psycopg2-binary
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/d7/1c/8d042630c5ff3c3e6d93c992bd7ecf516d577803b96781c6caa649bbf6e5/psycopg2-binary-2.9.3.tar.gz (380 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /private/var/folders/1_/_d2zc5n14ybdp1tgyd0pddb80000gn/T/pip-pip-egg-info-mfvu5r5l/psycopg2_binary.egg-info
      writing /private/var/folders/1_/_d2zc5n14ybdp1tgyd0pddb80000gn/T/pip-pip-egg-info-mfvu5r5l/psycopg2_binary.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/1_/_d2zc5n14ybdp1tgyd0pddb80000gn/T/pip-pip-egg-info-mfvu5r5l/psycopg2_binary.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/1_/_d2zc5n14ybdp1tgyd0pddb80000gn/T/pip-pip-egg-info-mfvu5r5l/psycopg2_binary.egg-info/top_level.txt
      writing manifest file '/private/var/folders/1_/_d2zc5n14ybdp1tgyd0pddb80000gn/T/pip-pip-egg-info-mfvu5r5l/psycopg2_binary.egg-info/SOURCES.txt'
      
      Error: pg_config executable not found.
      
      pg_config is required to build psycopg2 from source.  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'.
      
      If you prefer to avoid building psycopg2 from source, please install the PyPI
      'psycopg2-binary' package instead.
      
      For further information please check the 'doc/src/install.rst' file (also at
      <https://www.psycopg.org/docs/install.html>).
      
      [end of output]
  
  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.
(venv)  ✘  ~/Documents/workspace/learning_fastapi   master ±     

解决方法

# python v3.9
# RHEL  
sudo dnf install postgresql-devel python39-devel 
# Ubuntu 
sudo apt update
sudo apt install postgresql-dev  python39-dev 
# Mac 
brew install postgresql 

参考

https://stackoverflow.com/questions/11618898/pg-config-executable-not-found
https://www.psycopg.org/docs/install.html

posted on   Toliong  阅读(890)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示