My pants installation has somehow gotten completel...
# general
f
My pants installation has somehow gotten completely messed up. On Mac M3 Pro (arm) Tahoe 26.2. I'm using the
get-pants.sh
script installer (but I had been using brew at one time, I've also tried reinstalling via brew). I think the issue is it somehow keeps thinking it should use python 3.9, but I have no idea how it's inferring that. Weirdly, if I start a fresh repo, it seems to work. It's just in our main monorepo codebase that it breaks. Details in the thread. edit: OH HOLY MOLY. It's because I have a dir named
venv
and the tools.pex system is trying to run
python -m venv
which tries to execute that dir as a module, instead of the package. wow. that was gross.
Copy code
File "/Users/michaelmcdermott/Library/Caches/nce/75c2bcc055088e9d20109910c82960bfe4ec5c1ea481e2176002aad4d7049eab/cpython-3.9.23+20250612-aarch64-apple-darwin-install_only.tar.gz/python/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Users/michaelmcdermott/Library/Caches/nce/75c2bcc055088e9d20109910c82960bfe4ec5c1ea481e2176002aad4d7049eab/cpython-3.9.23+20250612-aarch64-apple-darwin-install_only.tar.gz/python/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/__main__.py", line 233, in <module>
    result, should_exit, is_globals = boot(
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/__main__.py", line 225, in boot
    result = bootstrap_pex(
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/pex_bootstrapper.py", line 673, in bootstrap_pex
    venv_pex = _bootstrap_venv(entry_point, interpreter=target)
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/pex_bootstrapper.py", line 740, in _bootstrap_venv
    return ensure_venv(pex.PEX(entry_point, interpreter=interpreter))
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/pex_bootstrapper.py", line 533, in ensure_venv
    virtualenv = Virtualenv.create_atomic(
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/venv/virtualenv.py", line 349, in create_atomic
    virtualenv = cls.create(
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/venv/virtualenv.py", line 315, in create
    interpreter.execute(args=args, env=env)
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/interpreter.py", line 1576, in execute
    stdout, stderr = Executor.execute(cmd, stdin_payload=stdin_payload, env=env, **kwargs)
  File "/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/unzipped_pexes/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/.bootstrap/pex/executor.py", line 99, in execute
    raise cls.NonZeroExit(cmd, process.returncode, stdout, stderr)
pex.executor.Executor.NonZeroExit: received exit code 1 during execution of `['/Users/michaelmcdermott/Library/Caches/nce/75c2bcc055088e9d20109910c82960bfe4ec5c1ea481e2176002aad4d7049eab/cpython-3.9.23+20250612-aarch64-apple-darwin-install_only.tar.gz/python/bin/python3.9', '-s', '-E', '-m', 'venv', '/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/venvs/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/936040e8807b5653804763be61a5e8a3ef1776cd.lck.work', '--without-pip', '--prompt', 'tools.pex']` while trying to execute `['/Users/michaelmcdermott/Library/Caches/nce/75c2bcc055088e9d20109910c82960bfe4ec5c1ea481e2176002aad4d7049eab/cpython-3.9.23+20250612-aarch64-apple-darwin-install_only.tar.gz/python/bin/python3.9', '-s', '-E', '-m', 'venv', '/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/venvs/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/936040e8807b5653804763be61a5e8a3ef1776cd.lck.work', '--without-pip', '--prompt', 'tools.pex']`
Error: Failed to establish atomic directory /Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/locks/configure-faadbdb4f04276731f0a009c66385aee890288a8a214de57183665144e82fb44. Population of work directory failed: Boot binding command failed: exit status: 1

Isolates your Pants from the elements.

Please select from the following boot commands:

<default> (when SCIE_BOOT is not set in the environment)  Detects the current Pants installation and launches it.
bootstrap-tools                                           Introspection tools for the Pants bootstrap process.
update                                                    Update scie-pants.

You can select a boot command by setting the SCIE_BOOT environment variable.
I've tried
rm -rf ~/Library/Caches/nce
to no avail
Also have tried
SCIE_BOOT=update pants
and
SCIE_BOOT=bootstrap-tools update
, same error
h
I've seen something similar when running in an activated venv. Is your venv active in the shell you're running this in? If so try deactivating temporarily. And either way, try running with
PYTHONPATH=""
?
f
i tried it with and without but if my theory is correct (and it was fixed by deleting the folder) then pythonpath should not matter (unless it too contains a "bad venv")
yup I've confirmed it. 1.
rm -rf ~/Library/Caches/nce
remove pants cache so it needs to create a venv 2.
mkdir venv
and add to
__init__.py
:
Copy code
import sys
import time

with open('/tmp/side_effects.txt', 'a') as fp:
  data = [el for el in sys.argv]
  data.append(time.time())
  fp.write(str(data) + '\n')
1. run
pants --version
2. it explodes 3.
cat /tmp/side_effects.txt
Copy code
['-m', '/Users/michaelmcdermott/Library/Caches/nce/dad0b67cd8eb77988214e15e5508871073f32621cc1339c96afa329ecd98b32f/bindings/pex_root/venvs/1/9f456f34c6ccd1199ac98e22b12277de7423dc45/936040e8807b5653804763be61a5e8a3ef1776cd.lck.work', '--without-pip', '--prompt', 'tools.pex', 1771959119.264045]
we see that it's trying to invoke it
and yeah
PYTHONPATH=""
does not fix it because it's trying to treat venv as a module. I think the fix would be the
-I
flag, but that's a python flag, not pants. Considering it's a pretty narrow corner case (you have to have a folder specifically called
venv
and it has to have a
__init__.py
) I'm not sure it's worth filing a bug per se but maybe it's worth the two line fix to check if that file exists and throw a warning?
c
I suspect that
venv
is not an uncommon name and a bug report would be welcome.
f
Sounds good. github issue fine?
c
Yep!
✅ 1
f
I chased it down and it looks like it's in fact a Pex issue so I also opened an issue over there
b
Thanks for the report @full-advantage-24495 - I should have Pex 2.90.2 out with the fix later today. I will say, your note about a superfund site is a gem. When you can't run
python -mvenv
in a directory, that's generally going to be a problem!
😁 1
Alright, the Pex fix is released in https://github.com/pex-tool/pex/releases/tag/v2.90.2. Baton passed to Pants folks to get scie-pants updated and released.
🙌 1
f
I'm like 90% sure the
.venv/__init__.py
file was created by Pycharm. It LOVES creating those automatically for some reason when you refactor. It's a pain in the ass cause most of the time I want explicit control of them (e.g namespace packages). But it shows how such a situation could arise for others and confuse the heck out of them (I consider myself very well versed in python at this point and it stumped me for a bit). Also you still support python 2? Absolute gigachad, though I don't envy you 😉 .
b
.venv
is fine,
venv
is not.
f
oh that's what I meant. And yeah i had a
venv
dir from a looong time back for a reason that now escapes me, but it was always just gitignored and never cleaned up ever XD I should run a git clean fd
b
No tool would create
venv/...
- that would be a very bad Python tool
f
no I probably did
python -m venv venv
at some point without realizing the implication immediately
b
That makes more sense.
f
this whole monorepo I'm working on is a frankenstein's monster of antipatterns and several years of folks not really understanding python best practices 🫠 Anyways, thanks for all your hard work on Pex! It's been fantastic for our CDK container deployments
b
Excellent. You're welcome.