2015-01-21 48 views
-3
[email protected]:~# pip install psycopg2 
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/local/lib/python2.7/dist-packages 

爲什麼PostgreSQL不能在python中工作?爲什麼PostgreSQL不能在Python中工作?

[email protected]:~$ python 
Python 2.7.8 (default, Oct 20 2014, 15:05:29) 
[GCC 4.9.1] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import postgresql 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named postgresql 
+1

你爲什麼要導入'postgresql'?你安裝的項目叫做'psycopg2'。是否有文檔或教程somwhere給你的印象模塊導入被稱爲'postgresql'? – 2015-01-21 07:47:57

+1

因爲你沒有閱讀文檔? http://initd.org/psycopg/docs/usage.html – bav 2015-01-21 07:44:56

回答

4

該模塊被稱爲psycopg2,導入它,而不是postgresql

import psycopg2 

演示:

>>> import psycopg2 
>>> psycopg2.__version__ 
'2.5.4 (dt dec pq3 ext)' 

有雖然PostgreSQL的純Python特定python3驅動程序稱爲py-postgresql。你可能有混合/提到它:

$ python3 
Python 3.4.0 (default, Apr 3 2014, 20:36:56) 
>>> import postgresql 
>>> postgresql.version 
'1.1.0' 
0

你應該導入psycopg2而不是postgresql

相關問題