Fixing the "Access Denied" (davey.pyd) Error During Hermes Desktop Installer Setup on Windows
If you’ve tried installing or updating the Hermes AI Agent desktop application on Windows, you might have run into a frustrating installer halt. The setup window suddenly stops and throws a red error banner saying:
INSTALL DIDN’T FINISH
Cannot remove item C:\Users\\AppData\Local\hermes\hermes-agent\venv\Lib\site-packages\davey\davey.cp311-win_amd64.pyd: Access to the path 'davey.cp311-win_amd64.pyd' is denied.
This error blocks the installer from completing, leaving you unable to open or use the agent. In this article, we’ll dive into the root cause of this file lock issue on Windows, explain why the installer got stuck, and show how we solved it both for your current setup and permanently in the installer code.
The Root Cause: Windows File Locking & Background Processes
Unlike Linux or macOS—which allow you to delete or replace files even if they are currently opened by active programs—Windows strictly enforces file locking.
If a file (especially executable code like python.exe or compiled C extensions like DLLs and .pyd files) is currently loaded into memory by any running process, Windows denies any attempt to delete, rename, or overwrite it. Doing so throws a native Access is denied (System Error Code 5) exception.
Why does this happen during the Hermes installation?
During an update or reinstall, the Hermes Setup wizard attempts to refresh or recreate the Python virtual environment (venv) directory:
- The installer checks if
venvexists. - If it does, it tries to delete it using
Remove-Item -Recurse -Force "venv"so it can install a clean set of dependencies. - However, if a background agent process (running as
pythonw.exeorpython.exefrom that virtual environment) is still active in the background, Windows lockspython.exeand any loaded C extensions—such asdavey.cp311-win_amd64.pyd(a native module used by Hermes). - The deletion fails midway, halting the installer with the Access Denied message.
Why the Initial Installer Cleanup Failed
The Hermes installer did have a process-cleanup mechanism in its PowerShell script (install.ps1), which looked like this:
if ($env:OS -eq "Windows_NT") {
$myPid = $PID
Write-Info "Stopping any running hermes processes before recreating venv..."
& taskkill /F /T /IM hermes.exe /FI "PID ne $myPid" 2>$null | Out-Null
Start-Sleep -Milliseconds 800
}
While this successfully terminated hermes.exe (the Electron GUI application), it failed to clean up the underlying background worker processes. When Electron spawns a Python daemon, terminating the main Electron process doesn't always cascade down to kill the children on Windows, leaving a orphan pythonw.exe running and locking the virtual environment.
The Solution
To solve this issue completely, we need to address two things: clearing the lock immediately so you can finish installing, and fixing the installer script so this never happens to users in the future.
1. The Immediate Quick Fix (For the User)
To instantly free the file lock and let the installer finish:
- Open Task Manager (
Ctrl + Shift + Esc). - Search for any processes named Python or pythonw.exe.
- Right-click and select End Task on those processes, particularly any running from
AppData\Local\hermes. - Alternatively, run the following command in PowerShell/CMD:
cmd taskkill /F /IM pythonw.exe - Go back to the Hermes Setup screen and click "Retry install". The installation will now succeed.
2. The Permanent Fix (In the Installer Code)
We updated the installation script (install.ps1) to target and terminate any running Python interpreters specifically tied to the virtual environment we are about to destroy.
Here is the enhanced cleanup logic added before the venv directory deletion:
if ($env:OS -eq "Windows_NT") {
$myPid = $PID
Write-Info "Stopping any running hermes processes before recreating venv..."
& taskkill /F /T /IM hermes.exe /FI "PID ne $myPid" 2>$null | Out-Null
# Also stop any running python/pythonw processes using the virtual environment
$venvPath = Join-Path $InstallDir "venv"
Get-Process -Name "python", "pythonw" -ErrorAction SilentlyContinue | Where-Object {
try {
$_.Path -and $_.Path.StartsWith("$venvPath\", [System.StringComparison]::OrdinalIgnoreCase)
} catch {
$false
}
} | ForEach-Object {
Write-Info "Stopping running venv process: $($_.Name) (PID $($_.Id))"
Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue
}
Start-Sleep -Milliseconds 800
}
Why this code works:
- It targets processes named
pythonandpythonw. - It uses
$_.Path.StartsWithto target only the processes running out of the specific virtual environment folder (venv/) for Hermes. This avoids accidentally killing a user's other active Python scripts or development environments. - It uses a
try/catchblock to handle cases where accessing the path of system-protected processes throws permission errors. - It calls
Stop-Process -Forceto cleanly terminate the running instances before callingRemove-Itemon the folder.
Summary
Windows file locks are a common headache for installer developers, but they can be easily managed by ensuring that any background daemons or workers are correctly cleaned up. By targeting virtual-environment-specific python processes during setup, Hermes updates are now robust, silent, and error-free on Windows machines.
Post a Comment for "Fixing the "Access Denied" (davey.pyd) Error During Hermes Desktop Installer Setup on Windows"