您需要安装用于构build服务器端扩展的postgresql-server-dev-XY或用于构build客户端应用程序的libpq-dev
我正在使用virtualenv处理Django项目,并将其连接到本地postgres数据库。 当我运行的项目是说,
ImportError: No module named psycopg2.extensions
然后我用这个命令来安装
pip install psycopg2
那么在安装过程中会出现以下错误。
Downloading/unpacking psycopg2==2.4.4 Downloading psycopg2-2.4.4.tar.gz (648kB): 648kB downloaded Running setup.py (path:/home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2/setup.py) egg_info for package psycopg2 Error: You need to install postgresql-server-dev-XY for building a server-side extension or libpq-dev for building a client-side application. Complete output from command python setup.py egg_info: running egg_info creating pip-egg-info/psycopg2.egg-info writing pip-egg-info/psycopg2.egg-info/PKG-INFO writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt' warning: manifest_maker: standard file '-c' not found Error: You need to install postgresql-server-dev-XY for building a server-side extension or libpq-dev for building a client-side application. ---------------------------------------- Cleaning up... Command python setup.py egg_info failed with error code 1 in /home/muhammadtaqi/Projects/MyProjects/OnlineElectionCampaign/venv/build/psycopg2 Storing debug log for failure in /home/muhammadtaqi/.pip/pip.log
使用下面这些命令,这将解决错误:
sudo apt-get install postgresql
然后开火:
sudo apt-get install python-psycopg2
最后:
sudo apt-get install libpq-dev
我只是从terminal运行这个命令,问题解决了,
sudo apt-get install -y postgis postgresql-9.3-postgis-2.1 pip install psycopg2
要么
sudo apt-get install libpq-dev python-dev pip install psycopg2
对我来说这个简单的命令解决了这个问题
sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev
那我可以这样做:
pip install psycopg2
对于Python 3,我做了:
sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev
然后我能够做到:
pip3 install psycopg2