ImportError: No module named psycopg2

2019-01-22 17:29发布

when installing process of openerp 6, i want to generate a config file with this command,

cd /home/openerp/openerp-server/bin/

./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg

but it was always showed a message

ImportError: No module named psycopg2

when i check for psycopg2 package, it's already installed,

Package python-psycopg2-2.4.5-1.rhel5.x86_64 already installed and latest version

Nothing to do

what's wrong with this? my server is centos, i've installed python 2.6.7.

Really need your help guys..

6条回答
我只想做你的唯一
2楼-- · 2019-01-22 17:44

Step 1: Install the dependencies

sudo apt-get install build-dep python-psycopg2

Step 2: Then run this command in your virtualenv

pip install psycopg2 

ref: Fernando Munoz

查看更多
贪生不怕死
3楼-- · 2019-01-22 17:49

try:

virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2

run python and try to import if you insist on installing it on your systems python try:

pip3 install psycopg2
查看更多
We Are One
4楼-- · 2019-01-22 17:50

For Python3

Step 1: Install Dependencies

sudo apt-get install python3 python-dev python3-dev

Step 2: Install

pip install psycopg2
查看更多
我只想做你的唯一
5楼-- · 2019-01-22 17:56

Please try to run the command import psycopg2 on the python console. If you get the error then check the sys.path where the python look for the install module. If the parent directory of the python-psycopg2-2.4.5-1.rhel5.x86_64 is there in the sys.path or not. If its not in the sys.path then run export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64> before running the openerp server.

查看更多
淡お忘
6楼-- · 2019-01-22 18:02

You need to install the psycopg2 module.

On CentOS: Make sure Python 2.7+ is installed. If not, follow these instructions: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/

# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs

# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py

# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py

$ easy_install-2.7 psycopg2

Even though this is a CentOS question, here are the instructions for Ubuntu:

$ sudo apt-get install python3-pip python-distribute python-dev
$ easy_install psycopg2

Cite: http://initd.org/psycopg/install/

查看更多
爷的心禁止访问
7楼-- · 2019-01-22 18:03

Recently faced this issue on my production server. I had installed pyscopg2 using

sudo pip install psycopg2

It worked beautifully on my local, but had me for a run on my ec2 server.

sudo python -m pip install psycopg2

The above command worked for me there. Posting here just in case it would help someone in future.

查看更多
登录 后发表回答