Skip to content

Commit 2faded7

Browse files
committed
Ensure Python venv module is installed
1 parent 1c1e3cb commit 2faded7

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

pioinstaller/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def python():
9090
% (platform.python_version(), util.get_pythonexe_path()),
9191
fg="green",
9292
)
93-
except (exception.IncompatiblePythonError, exception.DistutilsNotFound) as e:
93+
except (exception.IncompatiblePythonError, exception.PythonVenvModuleNotFound) as e:
9494
raise click.ClickException(
9595
"The Python %s (%s) interpreter is not compatible.\nReason: %s"
9696
% (platform.python_version(), util.get_pythonexe_path(), str(e))
@@ -123,7 +123,7 @@ def core_check(ctx, **kwargs):
123123
% (state.get("core_version"), state.get("platformio_exe")),
124124
fg="green",
125125
)
126-
except (exception.InvalidPlatformIOCore) as e:
126+
except exception.InvalidPlatformIOCore as e:
127127
raise click.ClickException(
128128
"Compatible PlatformIO Core not found.\nReason: %s" % str(e)
129129
)

pioinstaller/exception.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515

1616
class PIOInstallerException(Exception):
17-
1817
MESSAGE = None
1918

2019
def __str__(self): # pragma: no cover
@@ -26,15 +25,12 @@ def __str__(self): # pragma: no cover
2625

2726

2827
class IncompatiblePythonError(PIOInstallerException):
29-
3028
MESSAGE = "{0}"
3129

3230

33-
class DistutilsNotFound(PIOInstallerException):
34-
35-
MESSAGE = "Could not find distutils module"
31+
class PythonVenvModuleNotFound(PIOInstallerException):
32+
MESSAGE = "Could not find Python `venv` module"
3633

3734

3835
class InvalidPlatformIOCore(PIOInstallerException):
39-
4036
MESSAGE = "{0}"

pioinstaller/python.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ def check():
138138
raise exception.IncompatiblePythonError("Conda is not supported")
139139

140140
try:
141-
__import__("distutils.command")
141+
__import__("venv")
142+
# __import__("distutils.command")
142143
except ImportError:
143-
raise exception.DistutilsNotFound()
144+
raise exception.PythonVenvModuleNotFound()
144145

145146
# portable Python 3 for macOS is not compatible with macOS < 10.13
146147
# https://github.com/platformio/platformio-core-installer/issues/70
@@ -224,10 +225,10 @@ def find_compatible_pythons(
224225
log.debug(error)
225226
except UnicodeDecodeError:
226227
pass
227-
if error and "Could not find distutils module" in error:
228+
if error and "`venv` module" in error:
228229
# pylint:disable=line-too-long
229230
raise click.ClickException(
230-
"""Can not install PlatformIO Core due to a missed `distutils` package in your Python installation.
231+
"""Can not install PlatformIO Core due to a missed `venv` module in your Python installation.
231232
Please install this package manually using the OS package manager. For example:
232233
233234
$ apt-get install python3-venv

0 commit comments

Comments
 (0)