歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux教程

Ubuntu安裝psycopg2筆記

在Windows上和Ubuntu Linux上安裝psycopg2都遇到了點小插曲,記錄如下

Windows下:

1. 點擊這裡前往官網下載源代碼

2. 解壓

3. 運行python setup.py install報錯

解決辦法:官網提供了Windows版本安裝包的辦法,詳見這裡。

Ubuntu Linux下:

1. 前往官網下載源代碼

2. 解壓

3. 運行python setup.py install報錯

4. 直接運行apt-get install psycopg2報錯如下:

root@ www.linuxidc.com :~# 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.linuxidc.com :~# 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.linuxidc.com :~# 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

一些正常。

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved