https://pantsbuild.org/ logo
#general
Title
# general
p

polite-vase-75369

04/07/2021, 7:49 PM
This might be a weirdo mac problem, but recently pexs stopped working on my mac, saying no module named pkg_resources
Copy code
Lawrences-MacBook-Pro-2:aiq lawrencefinn$ python dist/app_admin_tool.pex 
Traceback (most recent call last):
  File "/Users/lawrencefinn/Documents/aiq/dist/app_admin_tool.pex/.bootstrap/pex/pex.py", line 394, in execute
  File "/Users/lawrencefinn/Documents/aiq/dist/app_admin_tool.pex/.bootstrap/pex/pex.py", line 92, in _activate
  File "/Users/lawrencefinn/Documents/aiq/dist/app_admin_tool.pex/.bootstrap/pex/environment.py", line 239, in activate
  File "/Users/lawrencefinn/Documents/aiq/dist/app_admin_tool.pex/.bootstrap/pex/environment.py", line 399, in _activate
  File "/Users/lawrencefinn/Documents/aiq/dist/app_admin_tool.pex/.bootstrap/pex/environment.py", line 143, in _update_module_paths
  File "/usr/local/Cellar/python@2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/lawrencefinn/.pex/code/7a8afd2b0ab97a76f9819ebfa3858979ce567b61/gen/__init__.py", line 1, in <module>
    __import__('pkg_resources').declare_namespace(__name__)
ImportError: No module named pkg_resources
This used to work, and it works fine on non-mac machines (and maybe other laptops). Im on pants 1.27.0
Using pants run works fine, btw
h

hundreds-father-404

04/07/2021, 7:53 PM
I'm wondering if one of your deps does not properly declare a dependency on `pkg_resources`/setuptools - many assume that it is present in your environment, which could explain why it's working for Linux users if they have it but you don't on your mac I think a way to test this is to add
setuptools==<version>
to requirements.txt, then add
3rdparty/python:setuptools
to your
dependencies
for the
python_binary
target. If that works, we can figure out the best approach to address this
p

polite-vase-75369

04/07/2021, 7:57 PM
ill give it a whirl
i also have a weird feeling this is pyenv related
Still doesn’t work 😞
🤔 1
h

hundreds-father-404

04/07/2021, 8:07 PM
I'm shooting in the dark a bit, but my next thought would be to try to install
setuptools
with the pip corresponding to
/usr/local/Cellar/python@2/2.7.17/Frameworks/Python.framework/Versions/2.7/lib/python2.7
Also, could you try something like
python3 dist/app_admin_tool.pex
? given that it fails with
python
(python2)
p

polite-vase-75369

04/07/2021, 8:08 PM
if i do
Copy code
python /Users/lawrencefinn/.pex/code/7a8afd2b0ab97a76f9819ebfa3858979ce567b61/gen/__init__.py
that works fine
hmmm python3 has a whole different error
one that is actually in my code
👍 1
so python2 on my laptop is just a poop ?
💩 1
h

hundreds-father-404

04/07/2021, 8:10 PM
K, so that suggests that indeed this is something wrong with that
python
binary, e.g. if it's missing pkg_resources. That's consistent that things work on Linux but not Mac, as those are using different Python interpreters to run the PEX
p

polite-vase-75369

04/07/2021, 8:11 PM
hmmm
a few years late is as good as every to upgrade python 😛
💯 1
h

hundreds-father-404

04/07/2021, 8:12 PM
On that note, see https://blog.pantsbuild.org/python-3-migrations/ for how Pants v2 can help to pull off a migration! I first got involved with Pants working on Py3 migrations, so a topic near and dear to my heart
p

polite-vase-75369

04/07/2021, 8:15 PM
I think this should be ok, considering that this code is a bit segregated from other code…. ill give it a whirl!
thanks
❤️ 1
e

enough-analyst-54434

04/08/2021, 12:07 AM
Useful data if you're willing to collect @polite-vase-75369 : 1. Grab a modern Pex PEX with tools:
curl -sSL <https://github.com/pantsbuild/pex/releases/download/v2.1.39/pex> > pex-2.1.39.pex
2. Use pex tools to extract some PEX-INFO metadata:
PEX_MODULE=pex.tools python2.7 pex-2.1.39.pex your.pex info | jq '.distributions,.requirements'
3. And compare to
PEX_MODULE=pex.tools python2.7 pex-2.1.39.pex your.pex repository info
Here
your.pex
is your pex and
python2.7
is shorthand for the full path to the python2.7 discussed above.
p

polite-vase-75369

04/08/2021, 2:12 PM
ill give that a whirl
@enough-analyst-54434 what should i be comparing? see if some version is off?
uhhh so it randomly started working after a reboot. but i should upgrade to python3 anyway. thanks for the help!
e

enough-analyst-54434

04/08/2021, 3:34 PM
If you could post or dm the output that would be easiest. Hopefully no names are sensitive.
p

polite-vase-75369

04/08/2021, 3:38 PM
well it started working, so i dunno if it is helpful anymore?
e

enough-analyst-54434

04/08/2021, 3:57 PM
It's up to you, but its always helpful to root cause and hopefully find a way to prevent flaky from ever happening again.
5 Views