Skip to content

"OSError: [WinError 145] The directory is not empty" while removing a virtual environment #6

@fohrloop

Description

@fohrloop

From time to time, when removing a virtual environment, a OSError: [WinError 145] is raised.

Example:

PS C:\repos\own-git-repos\some_project> python -m venvlink -d my-virtual-env
Deleting venv for "my-virtual-env"
11-28 19:59 venvlink     INFO     Removing C:\Python\venvs\my-virtual-env
Traceback (most recent call last):
  File "C:\Python\Python 3.8.6-64\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Python\Python 3.8.6-64\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\repos\own-git-repos\venvlink\venvlink\__main__.py", line 70, in <module>   
    delete_env(args)
  File "c:\repos\own-git-repos\venvlink\venvlink\__main__.py", line 60, in delete_env 
    vlink.delete_env(args.projectname.strip())
  File "c:\repos\own-git-repos\venvlink\venvlink\__init__.py", line 92, in delete_env 
    shutil.rmtree(folder)
  File "C:\Python\Python 3.8.6-64\lib\shutil.py", line 737, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Python\Python 3.8.6-64\lib\shutil.py", line 610, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Python\Python 3.8.6-64\lib\shutil.py", line 619, in _rmtree_unsafe
    onerror(os.rmdir, path, sys.exc_info())
  File "C:\Python\Python 3.8.6-64\lib\shutil.py", line 617, in _rmtree_unsafe
    os.rmdir(path)
OSError: [WinError 145] The directory is not empty: 'C:\\Python\\venvs\\my-virtual-env\\Lib'

This is somehow related to Windows using the files, as running the same command again will succesfully remove the virtual environment.

Suggesting that some retrying is added to the removal function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions