@@ -203,6 +203,7 @@ def find_compatible_pythons(
203203 candidates .insert (0 , sys .executable )
204204
205205 result = []
206+ missed_venv_module = False
206207 for item in candidates :
207208 if item in ignore_list :
208209 continue
@@ -224,26 +225,29 @@ def find_compatible_pythons(
224225 except UnicodeDecodeError :
225226 pass
226227 except subprocess .CalledProcessError as e :
227- error = None
228228 try :
229229 error = e .output .decode ()
230+ if error and "`venv` module" in error :
231+ missed_venv_module = True
230232 log .debug (error )
231233 except UnicodeDecodeError :
232234 pass
233- if error and "`venv` module" in error :
234- # pylint:disable=line-too-long
235- raise click .ClickException (
236- """Can not install PlatformIO Core due to a missed `venv` module in your Python installation.
237- Please install this package manually using the OS package manager. For example:
238-
239- $ apt-get install python3-venv
240-
241- (MAY require administrator access `sudo`)""" ,
242- )
243235 except Exception as e : # pylint: disable=broad-except
244236 log .debug (e )
245237
246238 if not result and raise_exception :
239+ if missed_venv_module :
240+ # pylint:disable=line-too-long
241+ raise click .ClickException (
242+ """Can not install PlatformIO Core due to a missed `venv` module in your Python installation.
243+ Please install this package manually using the OS package manager. For example:
244+
245+ $ apt-get install python3.%d-venv
246+
247+ (MAY require administrator access `sudo`)"""
248+ % (sys .version_info [1 ]),
249+ )
250+
247251 raise exception .IncompatiblePythonError (
248252 "Could not find compatible Python 3.6 or above in your system."
249253 "Please install the latest official Python 3 and restart installation:\n "
0 commit comments