Hi, I would like to ask about the problem that the...
# general
f
Hi, I would like to ask about the problem that the behavior changes depending on the setting of
pex_binary.layout
when running in docker.
Samples are followings: py
Copy code
import xgboost

def main():
    print(xgboost.__version__)

if __name__ == '__main__':
    main()
Dockerfile
Copy code
FROM $BASE
ENTRYPOINT ["/usr/local/bin/python3", "/bin/app"]
COPY /path/to/app /bin/app
BUILD
Copy code
python_sources()

pex_binary(
    name="binary",
    entry_point="main.py",
    layout="packed",
    execution_mode="venv",
    environment="linux_docker",
)

docker_image(
    name="docker",
    registries=["@hoge"],
    dependencies=[":binary"],
)
1:
pex_binary.layout = "packed"
Copy code
pants run hoge/xgb_test:docker
18:25:50.21 [INFO] Canceled: Building docker image base:latest
18:25:52.29 [INFO] Completed: Building docker image base:latest
18:25:52.35 [INFO] Canceled: Building docker image hoge/xgb_test:latest
18:25:58.83 [INFO] Completed: Building docker image hoge/xgb_test:latest
Traceback (most recent call last):
  File "/root/.pex/venvs/d7f1aae656b02d344f79eebdb5a705f8a9645494/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/pex", line 274, in <module>
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "<frozen runpy>", line 226, in run_module
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "/root/.pex/venvs/d7f1aae656b02d344f79eebdb5a705f8a9645494/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/lib/python3.11/site-packages/hoge/xgb_test/main.py", line 1, in <module>
    import xgboost as xgb
  File "/root/.pex/venvs/d7f1aae656b02d344f79eebdb5a705f8a9645494/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/lib/python3.11/site-packages/xgboost/__init__.py", line 7, in <module>
    from . import collective, dask, rabit
  File "/root/.pex/venvs/d7f1aae656b02d344f79eebdb5a705f8a9645494/779eb2cc0ca9e2fdd204774cbc41848e4e7c5055/lib/python3.11/site-packages/xgboost/collective.py", line 9, in <module>
    import numpy as np
ModuleNotFoundError: No module named 'numpy'
failure: Dependent libraries of xgboost have not been resolved.
2:
pex_binary.layout = 'loose' | 'zipapp'
Copy code
2.0.1
In this case, it succeeds.
Why do I get an error when executing from docker? Note that the
layout
setting does not seem to be affected when running from pex only.