I'm trying to run activitywatch on Ubuntu. I'm getting the folowing error:
code
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:24)──> 2025-04-14 10:58:24 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:25)──> 2025-04-14 10:58:25 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
┌─(~/Downloads/activitywatch-v0.13.2-linux-x86_64/activitywatch)──────────────────────────────────────────────────────────────────────────────────────────────(mbp@mbp-latitude:pts/0)─┐
└─(10:58:26)──> 2025-04-14 10:58:26 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133) 130 ↵ ──(Mon,Apr14)─┘
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
2025-04-14 10:58:27 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:133)
Traceback (most recent call last):
File "aw_watcher_window/main.py", line 115, in heartbeat_loop
File "aw_watcher_window/lib.py", line 64, in get_current_window
File "aw_watcher_window/lib.py", line 8, in get_current_window_linux
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
File "aw_watcher_window/xlib.py", line 13, in <module>
File "Xlib/display.py", line 89, in __init__
File "Xlib/display.py", line 71, in __init__
File "Xlib/protocol/display.py", line 166, in __init__
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'Authorization required, but no authorization protocol specified\n'
I wonder whether it should be run in some kind of isolated environment like pipx
Assistant
The error message you're encountering indicates that ActivityWatch is unable to connect to the X11 display server due to authorization issues. This problem often arises when a program running under one user account attempts to access the display server of another user without proper permissions.
Potential Causes:
Running as a Different User: If you're executing ActivityWatch with elevated privileges (e.g., using sudo), it may lack the necessary permissions to access your user's X11 session.
X11 Authorization Issues: The X11 server uses authorization protocols to control access. If these are not correctly configured, applications may be denied access.
Recommended Solutions:
Avoid Using sudo to Run ActivityWatch:
Ensure you're running ActivityWatch as your regular user without sudo. This approach maintains the correct environment variables and permissions for accessing the X11 display.
Grant Display Access to the Current User:
Use the xhost command to allow your user access to the X11 display:
bash
xhost +local:$USER
This command permits the local user to connect to the X11 server. For a more secure approach, you can specify the exact user:
bash
xhost +SI:localuser:your_username
Replace your_username with your actual username. This method is considered safer as it restricts access to the specified user[1].
Set the DISPLAY Environment Variable:
Ensure that the DISPLAY environment variable is correctly set:
bash
export DISPLAY=:0
This variable tells applications which display to connect to.
Verify X11 Authorization File (.Xauthority):
The .Xauthority file contains cookies used for authorization. Ensure that this file exists in your home directory and is accessible. If it's missing or corrupted, you might need to regenerate it[2].
Caution:
While using xhost + can resolve the issue by allowing all users to connect to the X11 server, it's not recommended due to security implications. It effectively disables access control, potentially exposing your display server to unauthorized access. Always prefer more restrictive and secure methods, such as specifying the exact user.
By implementing these solutions, you should be able to resolve the authorization issue and run ActivityWatch successfully on your Ubuntu system.