So, here I am, all set with my Python project on my EC2 instance, ready to hit the run button. Seems straightforward, right? Just install the dependencies listed in requirements.txt. But, well, things took an unexpected turn.

Python version issues

The initial hiccup – Python is not Python3. And to add to the mix, the requirements for psycopg2 specify version 2.9.9, and I need Python3.7.

Unable to upgrade Python, I opted for a workaround – installing Python3.7. Creating a virtual environment using python3.7 -m venv ./venv, I moved forward. Requirement satisfied, or so I thought. The next step, installing psycopg2-binary, also proved trickier than anticipated.

Dependencies, dependencies

It stubbornly refused a simple installation, insisting on building from source. This meant adding more friends to the mix – libpq-dev and python3.7-dev. It’s worth pointing out that I didn’t mind messing up with the instance because I have snapshots, and this machine was intended for experiments. So, a bit annoyed, I decided to go ahead and install those dependencies using apt. Simple, right? Well, not quite.

A 404 error popped up, indicating that the packages were playing hide-and-seek. A bit of URL digging revealed the culprit – the instance ran on an older Ubuntu version explained the source of the 404 error.

Interestingly, had I attempted this before November, this issue would have been a mystery. Postgres seemed to archive everything from the main repository at apt.postgresql.org for Ubuntu Bionic 18.04 which exactly my machine was running. A lesson learned from the trenches of software versions!

Information about outdated packages at wiki.postgresql.org source: https://wiki.postgresql.org/wiki/Apt

Additionally, I discovered that users do frequently inquire about missing packages: Archive for outdated packages source: https://www.postgresql.org/about/news/announcing-apt-archivepostgresqlorg-2024/

Solution

The solution involved appending the apt-archive URLs to /etc/apt/sources.list. Two lines did the trick:

deb https://apt-archive.postgresql.org/pub/repos/apt bionic-pgdg-archive main 
deb-src https://apt-archive.postgresql.org/pub/repos/apt bionic-pgdg-archive main

After an apt update, the missing packages were found, and the installation proceeded smoothly. Finally, my python3.7 -m pip install worked like a charm. The migration was a go!

Lessons learned

In conclusion, kudos to PostgreSQL for thinking about users with older versions. But finding this information wasn’t a walk in the park. I’m left wondering if setting up redirects for archived versions could spare others the plain frustration of a 404.

A grand takeaway: better be up-to-date in this ever-evolving tech landscape. The journey may be bumpy, but the lessons are worth it.