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.
CodePudding user response:
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'