Sam Hooke

Poetry: Fixing permission error when upgrading dulwich

When attempting to upgrade from Poetry v1.5.1 to v1.6.1 by running poetry self update I got the following error:

$ poetry self update
Updating Poetry version ...

Using version ^1.6.1 for poetry

Updating dependencies
...
Package operations: 77 installs, 14 updates, 0 removals
...
  • Updating dulwich (0.21.5 -> 0.21.6): Failed
...
  PermissionError: [WinError 5] Access is denied: 'C:\\Users\\<user>\\AppData\\Roaming\\pypoetry\\venv\\Lib\\site-packages\\~ulwich\\_diff_tree.cp310-win_amd64.pyd'

It appeared to be stuck trying to upgrade dulwich. Subsequent attempts to fix this by doing poetry self update then hit this error:

ModuleNotFoundError: No module named 'dulwich'

Presumably the dulwich installation got broken somehow? My initial attempts to fix this by re-installing Poetry still led to the same error, because the virtual environment persists between re-installs.

The fix §

I fixed this error with the following manual steps:

  1. Delete this directory, which was causing the PermissionError1: C:\Users\<user>\AppData\Roaming\pypoetry\venv\Lib\site-packages\~ulwich.
  2. Find the virtual env activate script at: C:\Users\<user>\AppData\Roaming\pypoetry\venv\Scripts.
  3. Run ./activate to enter the Poetry virtual env.
  4. Run pip install dulwich==0.21.6 to install dulwich v0.21.6 in the Poetry virtual env.

Then I was able to run poetry self update successfully.


  1. I did not need admin rights to delete this, so I’m not sure why Poetry was consistently getting PermissionError↩︎