添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

In installation process of OpenERP 6, I want to generate a config file with these commands:

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

But it always showed the message: ImportError: No module named psycopg2

When I checked for psycopg2 package, it's already installed. Package python-psycopg2-2.4.5-1.rhel5.x86_64 is already installed to its latest version. Nothing to do. What's wrong with this? My server is CentOS, I've installed Python 2.6.7.

The package installs for python2.4. If you have manually installed 2.6 then you also have to install all the other packages for 2.6. – Keith Oct 16, 2012 at 2:49 Please execute the following command to confirm the python system path. $ python -c 'import sys; print sys.path' – Taizo Ito Oct 16, 2012 at 4:15
sudo apt-get install build-dep python-psycopg2

Step 2: Run this command in your virtualenv

pip install psycopg2-binary 

Ref: Fernando Munoz

I found I also had to sudo apt-get install libpq-dev, as I don't have Postgresql installed on the machine I'm trying to install psycopg2 on. – Adam Parkin Oct 7, 2015 at 20:17 On Kubuntu 16.04 build-dep option doesn't work but sudo apt-get install python-psycopg2 works – Mugoma J. Okomba Feb 16, 2017 at 6:36

UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.

Reference: Psycopg 2.7.4 released | Psycopg

Just FYI - "If you are the maintainer of a published package depending on psycopg2 you shouldn’t use psycopg2-binary as a module dependency" see: psycopg.org/docs/install.html#psycopg-vs-psycopg-binary – Chad May 11, 2021 at 16:25

I faced the same issue and resolved it with following commands:

sudo apt-get install libpq-dev
pip install psycopg2
                This fixed the error message You need to install postgresql-server-dev-X.Y ... that I got after running sudo apt-get install build-dep python-psycopg2 (even thought I have postgresql installed already).
– webelo
                Sep 13, 2019 at 18:51
                @MuhammadInaamMunir --user : Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%\Python on Windows. You can check more info using pip install --help.
– ibnɘꟻ
                Nov 13, 2020 at 6:21

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.

Import Error on Mac OS If psycopg2 is getting installed but you are unable to import it in your .py file then the problem is libpq, its linkages, and the library openssl, on which libpq depends upon. The overall steps are reproduced below. You can check it step by step to know which is the source of error for you and then you can troubleshoot from there.

  • Check for the installation of the openssl and make sure it's working.

  • Check for installation of libpq in your system it may not have been installed or not linked. If not installed then install it using the command brew install libpq. This installs libpq library. As per the documentation

    libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.

  • Link libpq using brew link libpq, if this doesn't work then use the command: brew link libpq --force.
  • Also put in your .zshrc file the following
    export PATH="/usr/local/opt/libpq/bin:$PATH". This creates all the necessary linkages for libpq library .
  • Now restart the terminal or use the following command source ~/.zshrc.

  • Now use the command pip install psycopg2. It will work. This works, even when you are working in conda environment.

    N.B. pip install psycopg2-binaryshould be avoided because as per the developers of the psycopg2 library
  • The use of the -binary packages in production is discouraged because in the past they proved unreliable in multithread environments. This might have been fixed in more recent versions but I have never managed to reproduce the failure.

    This solved my problem! psycopg2 was clearly installed because i could successfully connect to my db, but when I tried to run a streamlit app that needed the results from the connection, i got the import not found statement. This solved it completely. Thank you! – Iris D Apr 10, 2022 at 18:30

    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.

    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/

    Hmm getting ez_setup.py is deprecated and when using it setuptools will be pinned to 33.1.1 – Arthur Nov 8, 2017 at 4:54

    For python3 on ubuntu, this worked for me:

    $sudo apt-get update
    $sudo apt-get install libpq-dev
    $sudo pip3 install psycopg2-binary
    

    Run into the same issue when I switch to Ubuntu from Windows 10.. the following worked for me.. this after googling and trying numerous suggestions for 2 hours...

    sudo apt-get install libpq-dev
    
    pip3 install psycopg2
    

    I hope this helps someone who has encountered the same problem especially when switching for windows OS to Linux(Ubuntu).

    check correctly if you had ON your virtual env of your peoject, if it's OFF then make it ON. execute following cammands:

    workon <your_env_name>
    python manage.py runserver
    

    It's working for me

    It's very simple, not sure why nobody mentioned this for mac before.

    brew install postgresql
    pip3 install psycopg2
    

    In simple terms, psycopg2 wants us to install postgres first.

    PS: Don't forget to upvote, so that it can help other people as well.

    Solved the issue with below solution :

  • Basically the issue due to _bz2.cpython-36m-x86_64-linux-gnu.so Linux package file. Try to find the the location.

  • Check the install python location ( which python3)- Example: /usr/local/bin/python3

  • copy the file under INSTALL_LOCATION/lib/python3.6

    cp -rvp /usr/lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so /usr/local/lib/python3.6
    

    Solved by following steps:

    sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
    sudo python get-pip.py
    sudo python -m pip install psycopg2-binary
                    I don't see how this adds anything not mentioned already back in 2013. Also, the question is about psycopg2, not psycopg.
    – Adriaan
                    Jan 16 at 9:31
                    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community
                    Jan 17 at 4:32
            

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •