1

I'm trying to set up a Python / Flask app with PostgreSQL on new cPanel hosting server that I have just purchased.

I've set up a virtualenv and managed to get all of my dependencies installed with

pip install -r requirements.txt

I cannot get psycopg2 to install, so have been trying to install psycopg2-binary instead, which I believe should work from what I have read in other posts.

Here's a snippet of the output:

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
    <https://www.psycopg.org/docs/install.html>).

    error: command '/opt/rh/devtoolset-7/root/usr/bin/gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/seasmuyr/virtualenv/seasonwork_live/3.8/bin/python3.8_bin -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5z014r2g/psycopg2-binary_bda4b7c8d43e4a26bf92e27771da2a93/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5z014r2g/psycopg2-binary_bda4b7c8d43e4a26bf92e27771da2a93/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-gq6h8obk/install-record.txt --single-version-externally-managed --compile --install-headers /home/seasmuyr/virtualenv/seasonwork_live/3.8/include/site/python3.8/psycopg2-binary Check the logs for full command output.

I've submitted a ticket with Namecheap but I'm not sure if they'll be able to provide much support with this issue. Any help would be much appreciated in resolving this and getting psycopg2 running for my PostgreSQL database.

  • Best guess is the OS and chip architecture on the host does not match any of the binary choices here [psycopg2-binary](https://pypi.org/project/psycopg2-binary/#files) so the installer is falling back to building from source. – Adrian Klaver Nov 26 '21 at 23:30
  • I'm thinking the issue there is that I don't have the permissions to access gcc when building from source? –  Nov 26 '21 at 23:38
  • That maybe so, but the point of `psycopg2-binary` is you shouldn't need to compile. – Adrian Klaver Nov 26 '21 at 23:52
  • I believe the issue is primarily down to the fact that I don't have root on the shared server. Namecheap support are going to try and install the modules for me, and hopefully that will resolve the issue. –  Nov 27 '21 at 01:01
  • I've tried solution in below thread and it worked. github.com/Patrowl/PatrowlDocs/issues/34 – Mandy May 25 '23 at 05:23

1 Answers1

2

I didn't manage to get psycopg working on the server in the end due to my limited privileges on the shared hosting.

Using pg8000 as a driver instead works just fine though for anyone who may come across this thread.

pip install pg8000

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql+pg8000://user:password@host:port/db'
  • I've tried solution in below thread and it worked. https://github.com/Patrowl/PatrowlDocs/issues/34 – Mandy May 25 '23 at 05:20