Lost a day of work after running python3 -m venv --clear .

Hey everyone,

I did something really stupid today, and I wanted to share it to avoid others making the same mistake.

I was experimenting with virtual environments (not being a Python expert) and ran:

python3 -m venv --clear .

I was in the right folder, or so I thought, but I didn’t realize that running this command would wipe out everything in the folder before creating the virtual environment. I ended up losing a whole day’s worth of work because I hadn’t pushed anything to Git today. My project had Next.js code and a .git folder, and I didn’t expect it to be deleted along with the Python stuff. I also had other non-Python code in the folder.

Here’s my question: Why doesn’t the --clear option prompt for confirmation before it deletes all files? I understand if it clears out Python-related files, but my folder also had a lot of non-Python code, including a .git folder, and I thought there would be a check or confirmation before doing this kind of deletion. I haven’t experienced running such code without confirmation before.

I thought it would at least check for other files in the directory before clearing. Has anyone else had this issue? Or am I just missing something important about how this works? Pardon me, I am not familiar with the venv stuff and maybe that was how it should work.

Just to clarify, I thought passing --clear will remove only the venv stuff.

Any advice or similar experiences would be helpful. I’m really frustrated about losing the work, and I’ll definitely be more careful moving forward. 😓

I think this is the source: https://github.com/python/cpython/blob/3.13/Lib/venv/__init__.py#L93-L101

Posted May 7, 2025, 2:33 PM UTC

66
Loading comments…