I encountered a very similar error caused by a very different issue. We use SLURM as the workload manager on a computer cluster. As such, we 'helpfully' set TMPDIR
to ensure users don't fill up the local file systems on the compute nodes.
In my case it boils down to an issue with venv:__init__.py:_setup_pip()
spawning a separate subprocess. The error initially given is deceptive because the real error is lost when calling subprocess.
After encountering the error, and keeping the state of the failed virtual environment the same, you can be clever and run the failed command (i.e. the subprocess) in the debugger. In my case it was
python -m pdb -m ensurepip --upgrade --default-pip
From there you can step through the debugger and figure out what the real issue was. In my case it boils down to something in pip/_internal/utils/temp_dir.py
(from the wheel file downloaded during install attempt) trying to create an adjacent directory, and it not quite working with our setting of TMPDIR
. The solution was to set export TMPDIR=/tmp
and it worked just fine.
Obviously, there is likely a whole subset of problems with very similar errors to that posted by @kahonmlg. Properly debugging the spawned process is the key to solving those problems. In my case the solution was just to set TMPDIR
, but obviously your mileage may vary.