Skip to content

Instantly share code, notes, and snippets.

@danielpodrazka
Created December 30, 2023 07:56
Show Gist options
  • Save danielpodrazka/e7349da6eef47c2655c768e9149d7afd to your computer and use it in GitHub Desktop.
Save danielpodrazka/e7349da6eef47c2655c768e9149d7afd to your computer and use it in GitHub Desktop.
Automatically compile psycopg
#!/bin/bash
# Update and Upgrade the System
sudo apt-get update
sudo apt-get upgrade -y
# Determine the installed Python version (major.minor)
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
# Install the corresponding version of python3.x-dev along with other necessary packages
sudo apt-get install -y python${PYTHON_VERSION}-dev libpq-dev gcc
# Find the correct version of PostgreSQL (if installed)
# and ensure pg_config is in the PATH
PG_CONFIG_PATH=$(find /usr/lib/postgresql/ -name pg_config -type f | sort -r | head -1)
if [ -n "$PG_CONFIG_PATH" ]; then
export PATH=$(dirname $PG_CONFIG_PATH):$PATH
else
echo "PostgreSQL is not installed or pg_config is not found."
exit 1
fi
# Install psycopg2
pip install psycopg2
# Verify the installation
if python -c 'import psycopg2' &> /dev/null; then
echo "psycopg2 successfully installed."
else
echo "There was an issue installing psycopg2."
fi
@danielpodrazka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment