How can I inspect the dependencies built into a PE...
# general
f
How can I inspect the dependencies built into a PEX built as a result of running
pants test
? I have pinned
numpy==1.26.4
in my
requirements.txt
, but a test is failing with an error that indicates the test environment is using
numpy>=2
. The numpy docs indicate that this error is only raised by
numpy>=2
. The code in question transitively depends on
numpy
by way of
tensorflow
which is also pinned to
tensorflow==2.11.0
in our
requirements.txt
. Building a PEX that contains the module in question and interacting with it manually does not raise the same error.
1
a
--keep-sandboxes=always
f
Thanks, this gets me partway there. I can’t seem to find any of the dependencies within the PEXes contained in the sandbox tempdir however. That said, when running with that flag that the test PEX was only including
tensorflow
because
numpy
is not an explicit dependency of the code under test. By adding
import numpy as np
to explicitly indicate a dependency on
numpy
, it is built into the test PEX and the test passes. It is not clear to me why/how an error message from Numpy v2 is being raised when it is not present in the environment and the distribution of
tensorflow==2.11.0
I am using has not been updated since 2022. I will share a minimal repo that reproduces the error shortly in case it is of interest to anyone.
a
I can take a look, if you can do it in the next like 30 minutes, I'm going to bed soon.
👍 1
a
Copy code
ERROR: Could not find a version that satisfies the requirement tensorflow==2.11.0 (from versions: 2.13.0rc0, 2.13.0rc1, 2.13.0rc2, 2.13.0, 2.13.1, 2.14.0rc0, 2.14.0rc1, 2.14.0, 2.14.1, 2.15.0rc0, 2.15.0rc1, 2.15.0, 2.15.1, 2.16.0rc0, 2.16.1, 2.16.2, 2.17.0rc0, 2.17.0rc1)
What python version are you using?
f
3.9 which is constrained in
pants.toml
a
Hm
f
I built the repro to mimic the internal repo I encountered this with. I’m trying to upgrade to Pydantic v2 and Python 3.9 (or later) now that some of our dependencies have finally upgraded to Pydantic v2. This is why the Pants version (2.17) and Python version are not exactly up to date.
a
I'm on a mac, btw...
f
Don’t let this keep you up. I just added
import numpy as np
to the problematic module so pants can infer the dependency and that workaround should be satisfactory for now.
a
Ah, okay, there's an x86 mac version
f
Same, intel mac. I’m guessing you’re on Apple silicon? I know that TF distros are not available for M* chips for some earlier versions
a
Yeah, they took my Linux one away and the only reason I agreed was because it was an m3 pro 😄
🚀 1
ugh, okay, I'm too bad at macs to figure out how to do this
f
lol no worries. thanks for trying
a
and too lazy to get my linux laptop. but, tests in pants get a pex with the requirements there, the code is copied in the sandbox
so if you kick around long enough in the sandbox, you should be able to find what's up
👍 1
if you look at
__run.sh
, you'll see what it's doing
there might be more than one level of magic in there, it's been a while since I had to debug something there
f
As far as I can tell Pants/PEX is not inferring that
tensorflow
requires
numpy
. Unclear why that is 🤷
a
That's not inferred, that comes from the package.
We have a constraint.txt file for this, might want to try that
f
Sorry, that’s what I meant
I’ll take a look at constraint.txt, thanks
a
We use it to stop compatible upgrades, but if you tell it not to use numpy > 2, it might give you an idea of what's causing it to use that.
👍 1
f
The odd thing is that it doesn’t seem to be building in any version of numpy. At least it’s not listed when building the PEX.
a
Data science stuff is always a disaster to upgrade 🙂
🎯 1
The message is about what you requested, whatever that pulls in will not be printed, but pex will get the dependencies.
👍 1
f
Ah ok
a
Like when you say
pip install tensorflow
, you don't say you want
numpy
, but you get it
👍 1
f
Makes sense. I’ll keep digging. Thanks again for the help.
a
Sure thing, it's my alcohol fuelled pants yak (or yak pants?) shaving night tonight 🙂
🍻 1
f
Ok I confirmed the test PEX contains Numpy v2.
tensorflow==2.11.0
requires
numpy>=1.20
as shown here which means pip will use the latest available version of
numpy
(v2+) which actually isn’t compatible. This is similar to the chaos caused by the release of the Pydantic v2 release where consumers did not pin
pydantic
to
<2
. What fun.
a
constraints.txt
will help you fix that.
👍 1
We have an internal tool that basically is a directory of internal tools, we apparently didn't pin pydantic < 2 either, as evidenced by it not working for me today 😄
f
lol, that release is the gift that keeps on giving
a
I'm a huge fan of pydantic, but even if I wasn't, can't really blame them
f
same and agreed. it’s a lesson to us all…