A developer renames their project folder and the venv breaks. Why?

Python interview question for Advanced practice.

Answer

The virtual environment contains absolute paths in the 'bin/' scripts pointing to the OLD location. Renaming the parent folder invalidates them.

Explanation

Venv scripts use hardcoded absolute paths to the interpreter. Renaming any parent directory changes the actual path, making the old hardcoded shebang invalid.

Related Questions