Fixing venv import path dynamically | Generated by AI
Here’s a comprehensive summary of the fix:
Problem
The /note command was failing with:
'ww' package not installed. Install with: pip install -e ~/projects/ww
Root Cause
Hermes Agent runs in its own isolated Python virtual environment at ~/.hermes/hermes-agent/venv/. The ww package was installed in the system Python (/opt/homebrew/bin/python3.11) but not in Hermes’ venv. When the plugin tried to from ww.note.create_note_from_clipboard import create_note_from_content, it failed because:
wwwasn’t in the venv’ssite-packages- Even if we installed it with
pip install -e ~/projects/ww, thepyperclipdependency was also missing
Solution (Two Parts)
Part 1: Plugin Code Change (~/.hermes/plugins/note/__init__.py)
Before:
try:
from ww.note.create_note_from_clipboard import create_note_from_content
except ImportError:
return "'ww' package not installed. Install with: pip install -e ~/projects/ww"
After:
try:
from ww.note.create_note_from_clipboard import create_note_from_content
except ImportError:
# Add ww project to path if not installed in current venv
import sys
ww_path = str(Path.home() / "projects" / "ww")
if ww_path not in sys.path:
sys.path.insert(0, ww_path)
try:
from ww.note.create_note_from_clipboard import create_note_from_content
except ImportError:
return "'ww' package not installed. Install with: pip install -e ~/projects/ww"
Why this works:
- Instead of requiring
wwto be pip-installed in every Python environment, the plugin now dynamically adds the source directory tosys.path - This allows importing directly from the source tree at
~/projects/ww/ - The fallback error message is preserved if the source directory doesn’t exist
Part 2: Installed Missing Dependency
~/.hermes/hermes-agent/venv/bin/python -m ensurepip
~/.hermes/hermes-agent/venv/bin/python -m pip install pyperclip
Why this was needed:
wwdepends onpyperclipfor clipboard operations- Even with the source directory in
sys.path, the import chain fails if dependencies aren’t installed pyperclipwas installed in the system Python but not in Hermes’ venv
Verification
~/.hermes/hermes-agent/venv/bin/python -c "
import sys
from pathlib import Path
ww_path = str(Path.home() / 'projects' / 'ww')
if ww_path not in sys.path:
sys.path.insert(0, ww_path)
from ww.note.create_note_from_clipboard import create_note_from_content
print('Import successful!')
"
# Output: Import successful!
Key Insight
Hermes plugins run inside Hermes’ isolated venv, not the system Python. When a plugin depends on local packages (like ww), you have two options:
- Install in the venv —
~/.hermes/hermes-agent/venv/bin/pip install -e ~/projects/ww(requires all dependencies) - Add to sys.path — dynamically inject the source directory (what we did)
Option 2 is more robust because it doesn’t require pip-installing the package and its dependencies in every environment.