Skip to main content

The day when my Python Virtual Environment broke

·256 words·2 mins
Author
Dr. Suresh Ramasamy
A tech afficianado who hails from South East Asia.

I never thought that a virtual environment would break. But here we are. This is my story.

I had a server that was long overdue for OS upgrade. It had been running Debian 11 for long time, and rightfully so as the critical package was only supported on Debian 11. Today, I happen to do some maintenance and found out that I am now free to move to Debian 12. And thats when trouble started (why does this happen to me?)

So, I used apt to upgrade the packages, then the OS, and then finally the packages again just to make sure everything runs on the new OS version. All worked well. Sort off.

I had a site that was running on Python-Flask-Gunicorn. Site was down. Logged in to check, to find that gunicorn wasn’t running. Okay, no biggie, I just go in and start the service. I got a bunch of errors saying that pip wasn’t available. Tried running pip manually, didn’t work. Exited the virtualenv, the OS version of pip was working fine. Nothing worked because the scripts were calling pip inside the virtualenv.

So, Hail Mary and decided to create a new virtual environment and run “pip install -r requirements.txt” (kids make sure your requirements.txt file is in working condition!). Made changes to my gunicorn helper scripts and viola! it worked! It’s alive!!!

So, today I learnt that OS upgrade breaks Python’s virtual environment. It seems (and I don’t know how) that the OS binding of Python has an influence to the virtualenvironment.