在Windows上和Ubuntu Linux上安装psycopg2都遇到了点小插曲,记录如下。
Windows下:
1. 点击http://www.initd.org/psycopg/前往官网下载源代码
2. 解压
3. 运行python setup.py install报错
解决办法:官网提供了Windows版本安装包的办法,详见http://www.stickpeople.com/projects/python/win-psycopg/
Ubuntu Linux下:
1. 前往官网下载源代码
2. 解压
3. 运行python setup.py install报错
4. 直接运行apt-get install psycopg2报错如下:
root@ www :~# easy_install psycopg2
Searching for psycopg2
Reading http://pypi.python.org/simple/psycopg2/
Reading http://initd.org/psycopg/
Reading http://initd.org/projects/psycopg2
Best match: psycopg2 2.4.4
Downloading http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.4.tar.gz#md5=639e014ea9ce3aa3306724f12d16d79b
Processing psycopg2-2.4.4.tar.gz
Running psycopg2-2.4.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-QddwSA/psycopg2-2.4.4/egg-dist-tmp-RbBPll
Error: You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
解决办法:
需要将“psycopg2”改为“python-psycopg2”:
root@ www :~# apt-get install python-psycopg2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
python-psycopg2
0 upgraded, 1 newly installed, 0 to remove and 193 not upgraded.
Need to get 630 kB of archives.
After this operation, 2,277 kB of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu/ oneiric/main python-psycopg2 amd64 2.4.2-1 [630 kB]
Fetched 630 kB in 15s (41.6 kB/s)
Selecting previously deselected package python-psycopg2.
(Reading database ... 171694 files and directories currently installed.)
Unpacking python-psycopg2 (from .../python-psycopg2_2.4.2-1_amd64.deb) ...
Setting up python-psycopg2 (2.4.2-1) ...
安装成功
测试一下:
root@ www :~# python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
一些正常。
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。