I am trying to configure Pants for the Windows Sub...
# general
r
I am trying to configure Pants for the Windows Subsystem for Linux. After doing a fresh Ubuntu install, discover that the default Python that has been automatically installed is Python 3.10.6. When I attempt to run Pants with this, I get:
Copy code
No valid Python interpreter found. For `pants_version = "2.16.0.dev0"`, Pants requires Python 3.7, 3.8, or 3.9 to run. Please check that a valid interpreter is installed and on your $PATH.
From the docs, it appears that Pants will support builds with more recent versions of Python, but Pants itself cannot run with a version of Python newer than 3.9. So I install 3.9 following these instructions: https://www.debugpoint.com/install-python-3-11-ubuntu/ (substituting 3.9 instead of 3.11). I make 3.9 the default following those instructions:
Copy code
bruce@groot:/mnt/c/git/semaphore-demo-python-pants$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.10   2         auto mode
  1            /usr/bin/python3.10   2         manual mode
* 2            /usr/bin/python3.9    1         manual mode
But when I try to run Pants I get:
Copy code
bruce@groot:/mnt/c/git/semaphore-demo-python-pants$ pants test ::
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 28, in <module>
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I try running the extra install command from here https://www.pantsbuild.org/docs/prerequisites#microsoft-windows:
Copy code
bruce@groot:/mnt/c/git/semaphore-demo-python-pants$ sudo apt install unzip python3-dev python3-distutils python3-venv gcc
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gcc is already the newest version (4:11.2.0-1ubuntu1).
python3-dev is already the newest version (3.10.6-1~22.04).
python3-distutils is already the newest version (3.10.6-1~22.04).
unzip is already the newest version (6.0-26ubuntu3.1).
python3-venv is already the newest version (3.10.6-1~22.04).
0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.
It seems like I missed a step or two somewhere...
e
So this:
Copy code
bruce@groot:/mnt/c/git/semaphore-demo-python-pants$ pants test ::
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 28, in <module>
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Looks to me like setting the default 3.9 using alternatives borked your system maybe and has ~nothing to do with Pants - a guess. I'd undo the alternatives bit. Pants just needs a Python 3.{7,8,9} to be visible on the PATH; that's all - it'll find it.
FWIW I'm currently a wsl2 Ubuntu 22.04 Pants / Pex / etc user.
I did not use deadsnakes to get my older Python, I just used pyenv - but that should not matter.
One thing to be wary of with debian packages for Python, and it looks like you already are, is that they slice out bits of the standard lib and do not include them by default - which is surprising! You have
python3-distutils
and `python3-venv`though in your steps above, which is good. That should get you a full real Python install.
Speak up if this continues to be vexing. I was reading tea leaves there a bit; so more pain details may help if there is more pain.