Created
December 30, 2023 07:56
-
-
Save danielpodrazka/e7349da6eef47c2655c768e9149d7afd to your computer and use it in GitHub Desktop.
Automatically compile psycopg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prompt-engineered with ChatGPT:
https://chat.openai.com/share/188145ab-8bc8-4e56-8fe2-710956e19654