AIR
AIR

Reputation: 825

Cant import psycopg2

I am trying to install postgresql_python. I downloaded the tarball and installed it using: python setup.py build python setup.py install

I got /usr/lib64/python2.4/site-packages/psycopg2/ with

> total 836
> -rw-r--r-- 1 root root  12759 Dec 11 18:18 errorcodes.py
> -rw-r--r-- 1 root root  14584 Dec 12 13:49 errorcodes.pyc
> -rw-r--r-- 1 root root  14584 Dec 12 13:49 errorcodes.pyo
> -rw-r--r-- 1 root root   5807 Dec 11 18:18 extensions.py
> -rw-r--r-- 1 root root   7298 Dec 12 13:49 extensions.pyc
> -rw-r--r-- 1 root root   7298 Dec 12 13:49 extensions.pyo
> -rw-r--r-- 1 root root  31495 Dec 11 18:18 extras.py
> -rw-r--r-- 1 root root  35124 Dec 12 13:49 extras.pyc
> -rw-r--r-- 1 root root  35124 Dec 12 13:49 extras.pyo
> -rw-r--r-- 1 root root   6177 Dec 11 18:18 __init__.py
> -rw-r--r-- 1 root root   5740 Dec 12 13:49 __init__.pyc
> -rw-r--r-- 1 root root   5740 Dec 12 13:49 __init__.pyo
> -rw-r--r-- 1 root root   8855 Dec 11 18:18 pool.py
> -rw-r--r-- 1 root root   8343 Dec 12 13:49 pool.pyc
> -rw-r--r-- 1 root root   8343 Dec 12 13:49 pool.pyo
> -rw-r--r-- 1 root root   3389 Dec 21 11:17 psycopg1.py
> -rw-r--r-- 1 root root   3182 Dec 21 11:22 psycopg1.pyc
> -rw-r--r-- 1 root root   3167 Dec 12 13:49 psycopg1.pyo
> -rwxr-xr-x 1 root root 572648 Dec 21 11:22 _psycopg.so drwxr-xr-x 2 root root   4096 Dec 21 10:38 tests
> -rw-r--r-- 1 root root   4427 Dec 11 18:18 tz.py
> -rw-r--r-- 1 root root   4325 Dec 12 13:49 tz.pyc
> -rw-r--r-- 1 root root   4325 Dec 12 13:49 tz.pyo

But in python shell when I am trying to import library, I got error:

>>> import psycopg2
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib64/python2.4/site-packages/psycopg2/__init__.py", line 76, in ?
    from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
ImportError: cannot import name _connect

I am running with Postgresql 9.2.

What am I missing here? Please let me know.

Thanks.

Upvotes: 1

Views: 1329

Answers (1)

Bartek
Bartek

Reputation: 15609

You most likely have to remove some existing packages related to psycopg2 within your root. Some common locations:

rm -r /usr/lib/python2.4/site-packages/psycopg2*
rm -r /usr/local/lib/python2.6/dist-packages/psycopg2*

However, I recommend setting up a virtualenv to house the packages for your Python app.

Check out virtualenv. It's easy to use once installed:

virtualenv myapp
. myapp/bin/activate
cd ~/your/postgres_lib/download
python setup.py install

This will install postgres libraries into your virtualenv (located under the myapp) folder. Then, whenever you want to run your app, you just need to activate the environment via

. myapp/bin/activate

Adjusting the path to myapp when necessary. There are helpers, like virtualenvwrapper to streamline this process.

Upvotes: 1

Related Questions