Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fohrloop opened this issue Nov 28, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@fohrloop
Copy link
Owner

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.

@fohrloop fohrloop added the bug Something isn't working label Nov 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant