curved-television-6568
11/17/2021, 6:55 PMcurved-television-6568
11/17/2021, 6:55 PMrun
goal and the package
goal builds a pex file.curved-television-6568
11/17/2021, 6:58 PM$ ./pants run helloworld:
19:51:54.29 [INFO] Completed: Resolving constraints.txt
19:51:54.98 [INFO] Completed: Extracting 3 requirements to build pex_binary.pex from repository.pex: ansicolors==1.1.8, setuptools<57,>=56.2.0, types-setuptools<58,>=56.2.0
19:51:55.64 [INFO] Completed: Building local_dists.pex
Ahoj, pantsbuild!
vs.
$ ./pants package helloworld:
19:52:10.24 [INFO] Wrote dist/helloworld/pex_binary.pex
$ ./dist/helloworld/pex_binary.pex
Traceback (most recent call last):
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/pex.py", line 475, in execute
self.activate()
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/pex.py", line 139, in activate
self._activated_dists = self._activate()
File "/root/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/pex.py", line 126, in _activate
activated_dists.extend(env.activate())
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/environment.py", line 288, in activate
self._activated_dists = self._activate()
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/environment.py", line 632, in _activate
resolved = self.resolve()
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/environment.py", line 468, in resolve
self._resolved_dists = self.resolve_dists(all_reqs)
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/environment.py", line 489, in resolve_dists
for qualified_req_or_not_found in self._root_requirements_iter(reqs):
File "/x/.pex/unzipped_pexes/836fdc93bba6481e342cc3716bff839aab08f8dc/.bootstrap/pex/environment.py", line 433, in _root_requirements_iter
raise ResolveError(message)
pex.environment.ResolveError: A distribution for setuptools could not be resolved in this environment.Found 1 distribution for setuptools that do not apply:
1.) The wheel tags for setuptools 56.2.0 are py3-none-any which do not match the supported tags of DistributionTarget(interpreter=PythonInterpreter('/usr/bin/python2.7', PythonIdentity('/usr/bin/python2.7', 'cp27', 'cp27mu', 'manylinux_2_31_x86_64', (2, 7, 18)))):
cp27-cp27mu-manylinux_2_31_x86_64
cp27-cp27mu-manylinux_2_30_x86_64
cp27-cp27mu-manylinux_2_29_x86_64
[...]
curved-television-6568
11/17/2021, 7:00 PMpex_binary
interpreter_constraints is default
interpreter_constraints
type: Iterable[str] | None
default: None
The Python interpreters this code is compatible with.
and according to the help message, it will use that of [python].interpreter_constraints
which is:
PANTS_PYTHON_INTERPRETER_CONSTRAINTS
interpreter_constraints
default: [
"CPython>=3.6,<4"
]
current value: [
">=3.7"
] (from pants.toml)
The Python interpreters your codebase is compatible with.
So it is a mystery to me why package produced a pex that attempts to use the 2.7 version of python..curved-television-6568
11/17/2021, 7:01 PMcurved-television-6568
11/17/2021, 7:03 PM$ python<TAB><TAB>
python python2 python2.7 python3 python3.8 python3.8-config python3-config python3-futurize python3-pasteurize
$ python --version
Python 2.7.18
$ python3 --version
Python 3.8.10
witty-crayon-22786
11/17/2021, 10:08 PMwitty-crayon-22786
11/17/2021, 10:08 PMunzip -c $pexfile PEX-INFO | jq .
curved-television-6568
11/18/2021, 6:21 AMunzip -p ..
😉
But no, the interpreter constraints field is
"interpreter_constraints": [],
curved-television-6568
11/18/2021, 6:22 AMexperimental_shell_command
perhaps..witty-crayon-22786
11/18/2021, 4:53 PMcurved-television-6568
11/18/2021, 5:08 PM"interpreter_constraints": [
"CPython>=3.7"
],
However, executing it still fails:
$ ./dist/helloworld/pex_binary.pex
pyenv: python3.7: command not found
The `python3.7' command exists in these Python versions:
3.7.12
Note: See 'pyenv help global' for tips on allowing both
python2 and python3 to be found.
(using pyenv
)
I tweaked the python search paths due to a bug (which I’m sure has been addressed, so not sure why it hit me now)
$ PANTS_PYTHON_SETUP_INTERPRETER_SEARCH_PATHS='["<PYENV>"]' ./pants package helloworld:
To circumvent:
ProcessExecutionFailure: Process 'Find interpreter for constraints: CPython>=3.7' failed with exit code 1.
...
File "/Users/x/.cache/pants/named_caches/pex_root/installed_wheels/a62f822b62a14ee4072eb45dc8505f01ca805f7b/pex-2.1.51-py2.py3-none-any.whl/pex/interpreter.py", line 666, in create_interpreter
raise cls.IdentificationError("Could not establish identity of {}.".format(binary))
pex.interpreter.IdentificationError: Could not establish identity of /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/pythonwrapper.app/Contents/MacOS/pythonwrapper.
curved-television-6568
11/18/2021, 5:10 PM$ python --version
Python 3.8.11
witty-crayon-22786
11/18/2021, 5:35 PMHowever, executing it still fails:
in this case, the issue is probably the shebang
line (which can be overridden)… it’s odd that your pyenv doesn’t install a python3.7
alias… i thought that that was standardwitty-crayon-22786
11/18/2021, 5:37 PMwitty-crayon-22786
11/18/2021, 5:43 PMcurved-television-6568
11/19/2021, 6:24 AMcurved-television-6568
11/19/2021, 6:26 AM$ which python3.7
/Users/aadt/.pyenv/shims/python3.7
$ python3.7 --version
pyenv: python3.7: command not found
The `python3.7' command exists in these Python versions:
3.7.12
Note: See 'pyenv help global' for tips on allowing both
python2 and python3 to be found.
curved-television-6568
11/19/2021, 6:27 AMwitty-crayon-22786
11/19/2021, 6:27 AMwitty-crayon-22786
11/19/2021, 6:28 AMwitty-crayon-22786
11/19/2021, 6:28 AMcurved-television-6568
11/19/2021, 6:28 AMenough-analyst-54434
11/20/2021, 5:48 PMcurved-television-6568
11/20/2021, 8:17 PMenough-analyst-54434
11/20/2021, 8:22 PMcurved-television-6568
11/20/2021, 8:24 PMcurved-television-6568
11/20/2021, 8:26 PM./pants run
works, while ./pants package
and then running the built pex file, does not work.enough-analyst-54434
11/20/2021, 8:31 PM<PYENV>
implementation I think. It exposes $(pyenv root)/versions/*/bin
but those are not on your PATH
for running the built PEX with, just the (potentially deactivated) shims.curved-television-6568
11/20/2021, 8:33 PMcurved-television-6568
11/20/2021, 8:33 PMrun
goal, I get this:
Completed: Find Python interpreter for constraints - Selected /Users/aadt/.pyenv/versions/3.7.12/bin/python3.7 to run PEXes with.
curved-television-6568
11/20/2021, 8:37 PMpackage
goal,curved-television-6568
11/20/2021, 8:38 PM#!/usr/bin/env python3.7
as it doesn’t use the path where it found it…enough-analyst-54434
11/20/2021, 9:30 PMcurved-television-6568
11/20/2021, 11:24 PMenough-analyst-54434
11/21/2021, 2:57 AMenough-analyst-54434
11/21/2021, 3:37 AMcurved-television-6568
11/21/2021, 6:44 AMcurved-television-6568
11/21/2021, 6:51 AMenough-analyst-54434
11/21/2021, 5:37 PM--interpreter-constraint >=3.6,<3.11
2. Ensure you actually have python3.{6,7,8,9,10}
on your PATH
(or on --python-path
).
3. Pick a shebang you know works for the machines you want top run this on, say --python-shebang '/usr/bin/env python3'
enough-analyst-54434
11/21/2021, 5:40 PMenough-analyst-54434
11/21/2021, 5:42 PMpython3.8 my_3.6-10.pex
will run the PEX with the python3.8
you chose since it matches interpreter constraints.enough-analyst-54434
11/21/2021, 5:43 PM--platform
iff pre-built wheels are available for all foreign platforms you want to target.curved-television-6568
11/21/2021, 6:22 PM