@@ -179,12 +179,12 @@ def find_compatible_pythons(
179179 for p in ignore_pythons or []:
180180 ignore_list .extend (glob .glob (p ))
181181 exenames = [
182- # "python3.11",
182+ "python3" , # system Python
183+ "python3.11" ,
183184 "python3.10" ,
184185 "python3.9" ,
185186 "python3.8" ,
186187 "python3.7" ,
187- "python3" ,
188188 "python" ,
189189 ]
190190 if util .IS_WINDOWS :
@@ -196,9 +196,14 @@ def find_compatible_pythons(
196196 if not os .path .isfile (os .path .join (path , exe )):
197197 continue
198198 candidates .append (os .path .join (path , exe ))
199- if sys .executable not in candidates :
200- candidates .insert (0 , sys .executable )
199+
200+ if sys .executable in candidates :
201+ candidates .remove (sys .executable )
202+ # put current Python to the top of list
203+ candidates .insert (0 , sys .executable )
204+
201205 result = []
206+ missed_venv_module = False
202207 for item in candidates :
203208 if item in ignore_list :
204209 continue
@@ -220,26 +225,29 @@ def find_compatible_pythons(
220225 except UnicodeDecodeError :
221226 pass
222227 except subprocess .CalledProcessError as e :
223- error = None
224228 try :
225229 error = e .output .decode ()
230+ if error and "`venv` module" in error :
231+ missed_venv_module = True
226232 log .debug (error )
227233 except UnicodeDecodeError :
228234 pass
229- if error and "`venv` module" in error :
230- # pylint:disable=line-too-long
231- raise click .ClickException (
232- """Can not install PlatformIO Core due to a missed `venv` module in your Python installation.
233- Please install this package manually using the OS package manager. For example:
234-
235- $ apt-get install python3-venv
236-
237- (MAY require administrator access `sudo`)""" ,
238- )
239235 except Exception as e : # pylint: disable=broad-except
240236 log .debug (e )
241237
242238 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+
243251 raise exception .IncompatiblePythonError (
244252 "Could not find compatible Python 3.6 or above in your system."
245253 "Please install the latest official Python 3 and restart installation:\n "
0 commit comments