Pointing Thonny to an Existing Virtual Environment

16 views
Skip to first unread message

Paul Naish

unread,
Aug 23, 2025, 4:06:37 PMAug 23
to thonny
I have a VENV ~/.venv/wc2. When I attempted to point the interpreter to ~/.venv/wc2/bin/python3 I receive all sorts of errors.

Then I use Thonny to create a test VENV at ~/.venv/test and it sets the interpreter to ~/.venv/test/bin/python3 and everything works.

How can I get Thonny to use my wc2 VENV?

Paul Naish

unread,
Aug 24, 2025, 9:07:16 AMAug 24
to thonny
In case it makes a difference, the VENV needed to be create with --system-site-packages

Paul Naish

unread,
Aug 24, 2025, 1:01:02 PMAug 24
to thonny
Doing some more exploration.

I created a new VENV at ~/.venv/abc and was able to get Thonny to accept the interpreter at ~/.venv/abc/bin/python3

I then pointed the interpreter back to WC2 and received the following error message


INTERNAL ERROR, got '' instead of 'OK'
---
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/thonny/plugins/cpython_frontend/cp_front.py", line 39, in __init__
    self._send_msg(ToplevelCommand("get_environment_info"))
  File "/usr/lib/python3/dist-packages/thonny/running.py", line 1157, in _send_msg
    self._proc.stdin.write(serialize_message(msg) + "\n")
BrokenPipeError: [Errno 32] Broken pipe

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/thonny/plugins/cpython_backend/cp_launcher.py", line 49, in <module>
    from thonny.common import PROCESS_ACK
ImportError: cannot import name 'PROCESS_ACK' from 'thonny.common' (/home/pi/.venv/wc2/lib/python3.11/site-packages/thonny/common.py)

Process ended with exit code
1

Paul Naish

unread,
Aug 24, 2025, 1:07:12 PMAug 24
to thonny
Problem solved (I think). When I saw this error

ImportError: cannot import name 'PROCESS_ACK' from 'thonny.common' (/home/pi/.venv/wc2/lib/python3.11/site-packages/thonny/common.py)

I couldn't understand why it was looking for a Thonny module in the VENV site-packages. When I investigated I had 2 Thonny package directories as well as the Thonny binary. 

Checking the PIP REQUIREMENTS.TXT I used to populate WC2, I found a reference to 'thonny=4.0.1'. This was likely a carry over from the REQUIREMENTS.TXT I created on the old BUSTER non-VENV implementation. 

Hopefully this helps others who have this issue.
Reply all
Reply to author
Forward
0 new messages