Vercel forces installations from `requirements.txt` file?

In a thread here I asked about a problem I’m having with psycopg 3 support. As a workaround, I thought I’d create a file named requirements-vercel.txt, which will I use instead of the default requirements.txt.

The only difference between the two files, is that requirements-vercel requires an older version of psycopg, that’s it.

The buildfiles.sh contains reference to the appropriate file:

echo "Step 7: Installing Python dependencies"
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade setuptools
python3 -m pip install -r requirements-vercel.txt
python3 -m pip uninstall -y psycopg psycopg2 psycopg2-binary
python3 -m pip install psycopg2-binary

However, it seems that something along the way is still installing dependencies from requirements.txt. I don’t have any other explanation for what’s happening. I also disabled the build cache to be sure.

As a proof: if I change the contents of requirements.txt to be identical to the contents of requirements-vercel.txt, the app works and does not error.

OK, I’m pretty sure that I proved this, and pretty sure that this happens after buildfiles.sh is running. I added the following snippet to the start of the run:

echo "Uninstalling all packages from requirements.txt"

if [ -f requirements.txt ]; then
  PACKAGES=$(python3 -m pip freeze | grep -F -f requirements.txt)
  if [ -n "$PACKAGES" ]; then
    echo "$PACKAGES" | xargs python3 -m pip uninstall -y
  else
    echo "No matching packages to uninstall."
  fi
fi

And there were no packages installed.
So sometime after requirements are installed from python3 -m pip install -r requirements-vercel.txt, they are installed from requirements.txt. Which is undesirable in my case.

I had hoped adding this to vercel.json would help:

"installCommand": "",

but it doesn’t.

OK. It’s proved by this point. I added this to the start of buildfiles.sh:

echo "rename requirements-vercel.txt to requirements.txt"
mv requirements-vercel.txt requirements.txt

And the app is “magically” working again. Magically in the very negative sense of the word. I’ve spent more hours on this than I should have if this behavior was documented.

Thanks for sharing what ended up working for you, @shxkm. I’m sorry to hear about the frustration - I’ll get this shared with our team as feedback.

We appreciate you sharing this! Hopefully helps others :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.