Error installing frappe: pycopg2 on Ubuntu 20.04

Trying to install a new bench with: bench init test, and getting this error:

 ERROR: Command errored out with exit status 1:
   command: /home/fpedrosa/devel/erpbr/env/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-zy1yydx2
       cwd: /tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/
  Complete output (38 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/psycopg2
  copying lib/extensions.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_range.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/compat.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/extras.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/sql.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/pool.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_json.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/errorcodes.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/tz.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/__init__.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/errors.py -> build/lib.linux-x86_64-3.9/psycopg2
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/psycopg
  cc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120005 -DHAVE_LO64=1 -I/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.0_1/include/python3.9 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-3.9/psycopg/adapter_asis.o -Wdeclaration-after-statement
  In file included from psycopg/adapter_asis.c:27:0:
  ./psycopg/psycopg.h:35:22: fatal error: libpq-fe.h: No such file or directory
  compilation terminated.
  
  It appears you are missing some prerequisite to build the package from source.
  
  You may install a binary package by installing 'psycopg2-binary' from PyPI.
  If you want to install psycopg2 from source, please install the packages
  required for the build and try again.
  
  For further information please check the 'doc/src/install.rst' file (also at
  <http://initd.org/psycopg/docs/install.html>).
  
  error: command '/home/linuxbrew/.linuxbrew/bin/cc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2-binary
    ERROR: Command errored out with exit status 1:
     command: /home/fpedrosa/devel/erpbr/env/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fzyrs5cr/install-record.txt --single-version-externally-managed --compile --install-headers /home/fpedrosa/devel/erpbr/env/include/site/python3.9/psycopg2-binary
         cwd: /tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/
    Complete output (38 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/psycopg2
    copying lib/extensions.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/_range.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/compat.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/extras.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/sql.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/pool.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/_json.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/errorcodes.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/tz.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/__init__.py -> build/lib.linux-x86_64-3.9/psycopg2
    copying lib/errors.py -> build/lib.linux-x86_64-3.9/psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/psycopg
    cc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120005 -DHAVE_LO64=1 -I/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.0_1/include/python3.9 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-3.9/psycopg/adapter_asis.o -Wdeclaration-after-statement
    In file included from psycopg/adapter_asis.c:27:0:
    ./psycopg/psycopg.h:35:22: fatal error: libpq-fe.h: No such file or directory
    compilation terminated.
    
    It appears you are missing some prerequisite to build the package from source.
    
    You may install a binary package by installing 'psycopg2-binary' from PyPI.
    If you want to install psycopg2 from source, please install the packages
    required for the build and try again.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <http://initd.org/psycopg/docs/install.html>).
    
    error: command '/home/linuxbrew/.linuxbrew/bin/cc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/fpedrosa/devel/erpbr/env/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0jbkwfv1/psycopg2-binary_5efacec303564e72b9dfeedc310de123/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-fzyrs5cr/install-record.txt --single-version-externally-managed --compile --install-headers /home/fpedrosa/devel/erpbr/env/include/site/python3.9/psycopg2-binary Check the logs for full command output.

I already have pycopg2 installed, but still appears this error.

How to fix that?

Thanks!

In a terminal, cd frappe-benchthen bench console

import sys
import psycopg2

If it cannot load the module exit from the bench console , try sudo apt install python3-psycopg2 and try again

got this:

bench console   
/home/fpedrosa/devel/erpbr/env/bin/python: Error while finding module specification for 'frappe.utils.bench_helper' (ModuleNotFoundError: No module named 'frappe')

Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/bin/bench", line 8, in <module>
    sys.exit(cli())
  File "/home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/site-packages/bench/cli.py", line 46, in cli
    if sys.argv[1] in get_frappe_commands() + ["--site", "--verbose", "--force", "--profile"]:
TypeError: unsupported operand type(s) for +: 'NoneType' and 'list'

Already installed via apt:

➜ sudo apt install python3-psycopg2
[sudo] password for fpedrosa: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-psycopg2 is already the newest version (2.8.5-1~pgdg20.04+1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

Does the same happen in a python3 session?

How was frappe installed?

How to force to use python3? I just type: bench init myapp

I just follow Install Instructions on frappe website: Installation

Using Debian/Ubuntu

Did cd ~ , then bench init frappe-bench complete without error?

Then bench start and bench migrate-env python3.x should get the python3 environment. (replace x with whatever version python3 is installed)

No, it’s failing:

➜ bench init frappe-bench
$ /home/linuxbrew/.linuxbrew/bin/virtualenv -q env -p python3

Getting frappe
$ git clone https://github.com/frappe/frappe.git  --depth 1 --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 3007, done.
remote: Counting objects: 100% (3007/3007), done.
remote: Compressing objects: 100% (2822/2822), done.
remote: Total 3007 (delta 404), reused 1055 (delta 117), pack-reused 0
Receiving objects: 100% (3007/3007), 13.08 MiB | 7.82 MiB/s, done.
Resolving deltas: 100% (404/404), done.

Installing frappe
$ frappe-bench/env/bin/pip install -q -U -e frappe-bench/apps/frappe 
  ERROR: Command errored out with exit status 1:
   command: /home/fpedrosa/frappe-bench/env/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-e96h56k3/psycopg2-binary_8684cc4ecaba4432876b7a46fbb92e09/setup.py'"'"'; __file__='"'"'/tmp/pip-install-e96h56k3/psycopg2-binary_8684cc4ecaba4432876b7a46fbb92e09/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-3mhqzm97
       cwd: /tmp/pip-install-e96h56k3/psycopg2-binary_8684cc4ecaba4432876b7a46fbb92e09/
  Complete output (38 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/psycopg2
  copying lib/extensions.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_range.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/compat.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/extras.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/sql.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/pool.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_json.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/_lru_cache.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/errorcodes.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/tz.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/__init__.py -> build/lib.linux-x86_64-3.9/psycopg2
  copying lib/errors.py -> build/lib.linux-x86_64-3.9/psycopg2
  running build_ext
  building 'psycopg2._psycopg' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/psycopg
  cc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -O3 -Wall -fPIC -DPSYCOPG_VERSION=2.8.4 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=120005 -DHAVE_LO64=1 -I/home/linuxbrew/.linuxbrew/Cellar/python@3.9/3.9.0_1/include/python3.9 -I. -I/usr/include/postgresql -I/usr/include/postgresql/12/server -c psycopg/adapter_asis.c -o build/temp.linux-x86_64-3.9/psycopg/adapter_asis.o -Wdeclaration-after-statement
  In file included from psycopg/adapter_asis.c:27:0:
  ./psycopg/psycopg.h:35:22: fatal error: libpq-fe.h: No such file or directory
  compilation terminated.
  
  It appears you are missing some prerequisite to build the package from source.
  
  You may install a binary package by installing 'psycopg2-binary' from PyPI.
  If you want to install psycopg2 from source, please install the packages
  required for the build and try again.
  
  For further information please check the 'doc/src/install.rst' file (also at
  <http://initd.org/psycopg/docs/install.html>).
  
  error: command '/home/linuxbrew/.linuxbrew/bin/cc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2-binary

maybe the problem is trying to use python3 instead of python2 ?

The weird stuff is trying to install postgreSQL driver… frappe use mariadb, right?!

Found the solution, on ubuntu need to install this:

sudo apt install libpq-dev

1 Like