incalculable-france-51377
02/19/2024, 3:12 PMERROR: Package 'instructor' requires a different Python: 3.9.18 not in '<4.0,>=3.10' . this is running inside a docker container based on the python:3.10.12 image which only contains python 3.10.12. i dug a little and found that when pants bootstraps itself, it installs a different python version in its own virtualenv. in this case, it's installed python 3.9.18. when pants runs, it's using this version and causing issues with upgrading this package. among other settings i have the following in my `pants.toml`:
[python]
enable_resolves = true
interpreter_constraints = ['CPython==3.10.12']
can someone help me understand why pants isn't respecting the interpreter_constraints parameter or using the system python? this is using pants 2.17.0broad-processor-92400
02/19/2024, 6:05 PMbroad-processor-92400
02/19/2024, 6:06 PMshebang is a suggested workaround for that version of pants.incalculable-france-51377
02/19/2024, 6:17 PMdocker_image which is defined like this:
docker_image(
name = "email_service_image",
dependencies = [":binary"],
repository = "<http://registry.fly.io/email_service|registry.fly.io/email_service>",
tags = [
"latest",
"<http://registry.fly.io/email_service:latest|registry.fly.io/email_service:latest>",
],
)
the binary dependency is defined as follows:
pex_binary(
name = "binary",
dependencies = [
":lib",
":celery_with_monitor",
],
execution_mode = "venv",
include_tools = True,
# Optimal settings for Docker builds
layout = "packed",
platforms = [
"manylinux_2_17_x86_64-cp-310-cp310",
"manylinux_2_17_aarch64-cp-310-cp310",
"macosx_13_0_arm64-cp-310-cp310",
],
shebang = "#!/usr/bin/env python",
)incalculable-france-51377
02/19/2024, 6:18 PMshebang definition and it doesn't appear to have any impact.incalculable-france-51377
02/19/2024, 6:18 PMpants package email_service:email_service_imagebroad-processor-92400
02/19/2024, 7:00 PMincalculable-france-51377
02/19/2024, 7:09 PM19:07:52.45 [INFO] Completed: Building local_dists.pex
19:08:07.66 [INFO] Completed: Building 37 requirements for email_service/binary.pex from the 3rdparty/python/default.lock resolve: beautifulsoup4==4.12.2, celery==5.3.1, fastapi==0.103.0, flower==2.0.1, google-api-python-client... (652 characters truncated)
19:08:07.67 [ERROR] 1 Exception encountered:
Engine traceback:
in `package` goal
ProcessExecutionFailure: Process 'Building 37 requirements for email_service/binary.pex from the 3rdparty/python/default.lock resolve: beautifulsoup4==4.12.2, celery==5.3.1, fastapi==0.103.0, flower==2.0.1, google-api-python-client==2.91.0, google-auth-httplib2==0.1.0, google-auth-oauthlib==1.0.0, google-cloud-vision==3.5.0, instructor==0.5.2, langsmith==0.0.69, loguru==0.7.1, nltk==3.6.5, openai==1.3.7, psycopg2-binary==2.9.6, pydantic==2.5.3, pypdf==3.12.0, python-dateutil==2.8.2, python-dotenv==1.0.0, python-jose[cryptography]==3.3.0, pytz==2023.3, redis==4.5.4, requests==2.31.0, resend==0.7.2, sentry-sdk==1.34.*, sentry-sdk[celery]==1.34.*, sentry-sdk[fastapi]==1.34.*, sqlalchemy==2.0.23, tiktoken==0.4.0, types-beautifulsoup4, types-python-dateutil, types-pytz, types-requests, types-urllib3, typing-extensions==4.8.*, unidecode==1.3.7, urllib3==1.26.*, uvicorn==0.21.1' failed with exit code 1.
stdout:
stderr:
There was 1 error downloading required artifacts:
1. instructor 0.5.2 from <https://files.pythonhosted.org/packages/3d/57/35e22db00463ac2a2f57e7b8823d0084c5e83f69d518313bdfbf61764463/instructor-0.5.2-py3-none-any.whl>
ERROR: Package 'instructor' requires a different Python: 3.9.18 not in '<4.0,>=3.10'
Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.incalculable-france-51377
02/19/2024, 7:11 PM# pants
Downloading <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tDownloading> <https://github.com/indygreg/python-build-standalone/releases/download/20240107/cpython-3.9.18%2B20240107-aarch64-unknown-linux-gnu-install_only.tBootstrapping> Pants 2.17.0
Installing pantsbuild.pants==2.17.0 into a virtual environment at /root/.cache/nce/d4d446890167dccc8fe0f286a7030d591d4ac22718c0ee941000c26ab7c2f7ec/bindings/venvs/2.17.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 26.3 MB/s eta 0:00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 819.3/819.3 kB 48.0 MB/s eta 0:00:00
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.4/65.4 kB 15.4 MB/s eta 0:00:00
New virtual environment successfully created at /root/.cache/nce/d4d446890167dccc8fe0f286a7030d591d4ac22718c0ee941000c26ab7c2f7ec/bindings/venvs/2.17.0.
19:07:02.73 [INFO] Initializing scheduler...
19:07:07.63 [INFO] Scheduler initialized.
No goals specified.
Use `pants help` to get help.
Use `pants help goals` to list goals.broad-processor-92400
02/19/2024, 7:36 PMincalculable-france-51377
02/19/2024, 7:45 PMrefined-addition-53644
02/19/2024, 8:01 PMplatforms which is discouraged in pex_binary. Try with --complete-platforms
Huon has provided a great write-up here. It talks about lambda but check the Docker image artefacts from PEXincalculable-france-51377
02/19/2024, 8:15 PMincalculable-france-51377
02/19/2024, 8:52 PMplatforms from the pex_binary goal, but then i can't run the docker container locally (using osx). it returns if i add complete_platforms , but i can once again run the docker container locally:
# generated by running:
# docker run -it --platform linux/arm64 python:3.10.12 bash -c 'pip install pex; pex3 interpreter inspect --markers --tags'
# docker run -it --platform linux/amd64 python:3.10.12 bash -c 'pip install pex; pex3 interpreter inspect --markers --tags'
#
# learned from here: <https://github.com/pantsbuild/pants/discussions/18756>
files(
name="docker_python_3_10",
sources=["docker_python_3_10_*.json"]
)
pex_binary(
name = "binary",
dependencies = [
":lib",
":celery_with_monitor",
],
execution_mode = "venv",
include_tools = True,
# Optimal settings for Docker builds
layout = "packed",
complete_platforms = [":docker_python_3_10"]
)curved-television-6568
02/20/2024, 9:24 AMshould i expect pants to be downloading python version 3.9.18 at any point?yes, when bootstrapping pants, it installs a Python that it is compatible with, that has nothing to do with the Python you use for your own project.
incalculable-france-51377
02/20/2024, 1:55 PMable-advantage-61346
04/02/2024, 2:09 PMincalculable-france-51377
04/02/2024, 2:22 PMinstructor or something w/ pants/pex? i've looked at the instructor config and it requires python 3.10 or higher, but i can't tell if poetry is building their wheel correctly. i've also tried upgrading the pex cli version but this doesn't change anything.
my 'solution' has been to have 2 builds - one for local and one in GHA. for GHA, i don't have the complete_platforms spec. for local, i do.incalculable-france-51377
04/02/2024, 2:24 PMpex_binary(
name = "binary",
dependencies = [
":lib",
":celery_with_monitor",
],
execution_mode = "venv",
include_tools = True,
# Optimal settings for Docker builds
layout = "packed",
)
pex_binary(
name = "binary_osx",
dependencies = [
":lib",
":celery_with_monitor",
],
execution_mode = "venv",
include_tools = True,
# Optimal settings for Docker builds
layout = "packed",
complete_platforms = [":docker_python_3_10"]
)
then, 2 docker_image targets and 2 docker filesable-advantage-61346
04/02/2024, 2:56 PMERROR: Package 'pbipy' requires a different Python: 3.9.18 not in '>=3.10'incalculable-france-51377
04/02/2024, 3:06 PMable-advantage-61346
04/02/2024, 8:09 PMpants test :: followed by pants publish ::. Looks like the test step manages to build all the pex-files, which the package step is not able to do.incalculable-france-51377
04/02/2024, 8:16 PMincalculable-france-51377
04/02/2024, 11:40 PMbroad-processor-92400
04/02/2024, 11:54 PMincalculable-france-51377
04/03/2024, 1:04 PMjobs:
search_api_deploy:
name: Deploy app
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup fly
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Setup pants
uses: pantsbuild/actions/init-pants@v5-scie-pants
# This action bootstraps pants and manages 2-3 GHA caches.
# See: <http://github.com/pantsbuild/actions/tree/main/init-pants/|github.com/pantsbuild/actions/tree/main/init-pants/>
with:
# v0 makes it easy to bust the cache if needed
# just increase the integer to start with a fresh cache
gha-cache-key: v1
# The Python backend uses named_caches for Pip/PEX state,
# so it is appropriate to invalidate on lockfile changes.
named-caches-hash: ${{ hashFiles('python-default.lock') }}
# If you're not using a fine-grained remote caching service (see <https://www.pantsbuild.org/docs/remote-caching>),
# then you may also want to preserve the local Pants cache (lmdb_store). However this must invalidate for
# changes to any file that can affect the build, so may not be practical in larger repos.
# A remote cache service integrates with Pants's fine-grained invalidation and avoids these problems.
cache-lmdb-store: "true" # defaults to 'false'
# Note that named_caches and lmdb_store falls back to partial restore keys which
# may give a useful partial result that will save time over completely clean state,
# but will cause the cache entry to grow without bound over time.
# See <https://pants.readme.io/docs/using-pants-in-ci> for tips on how to periodically clean it up.
# Alternatively you change gha-cache-key to ignore old caches.
- name: Lint
run: |
pants lint ::
- name: Typecheck
run: |
pants check ::
- name: Publish image
run: |
flyctl auth docker
pants --tag="-no_ci" test :: || true
IMAGE_TAG=latest pants publish api_search:api_search_image
after the line pants --tag="-no_ci" test :: || true was added, the publish step worksincalculable-france-51377
04/03/2024, 4:25 PMERROR: Package 'instructor' requires a different Python: 3.9.18 not in '<4.0,>=3.10'broad-processor-92400
04/03/2024, 9:53 PMpants test :: running first sometimes fixing the problem (if the 'magic' process is required for a test and the test has changed, it'll be run and seed the named cache, but if those tests don't need to run, the named cache will be left unseeded).
If you run locally with IMAGE_TAG=latest pants --named-caches-dir=$(mktemp -d) package api_search:api_search_image does it reproduce the problem? That sets https://www.pantsbuild.org/2.19/reference/global-options#named_caches_dir to a fresh temporary directory, i.e. simulating running without whatever magic seeds the cache.
If that doesn't reproduce, could you try in CI with an invocation like:
pants --force --tag="-no_ci" test :: || true
IMAGE_TAG=latest pants package api_search:api_search_image
IMAGE_TAG=latest pants --named-caches-dir=$(mktemp -d) package api_search:api_search_image
(Changes being: add --force to test to ensure they all run, switching publish to package so we're not mutating your infrastructure for these tests 😄 , and adding the tempdir-named-cache line second)
If the first package work but the second fails, that aligns with my theory that it may be a named-caches issue.incalculable-france-51377
04/03/2024, 11:30 PMIMAGE_TAG=test pants --named-caches-dir=$(mktemp -d) package api_search:api_search_image locally (osx) reproduces the problem. no issues running IMAGE_TAG=test pants package api_search:api_search_imagebroad-processor-92400
04/04/2024, 12:12 AMsome/subdirectory:: paths (NB. definitely needs a fresh tempdir each time)
dir=$(mktemp -d)
pants --force --named-caches-dir=$dir test some/subdirectory::
IMAGE_TAG=test pants --named-caches-dir=$(mktemp -d) package api_search:api_search_image
You might be able to guess at a better way to do that knowing your code (e.g. this is likely to involve a test that requires the instructor package).
Once it's narrowed down like that, it'd be good to cut out all the irrelevant stuff, e.g. if the test can become just a python_tests() target with one file containing only import instructor , and the packaged artifact can be cut down to a single pex_binary target also with just import instructor ... that'd be amazing (but there might be more going on), and then hopefully we can make a standalone repository reproducing the problem.able-advantage-61346
04/04/2024, 8:21 AMbroad-processor-92400
04/05/2024, 10:57 PMbroad-processor-92400
04/06/2024, 3:51 AMbroad-processor-92400
04/08/2024, 1:32 AMpex_binary target that does nothing but depend on the problematic packages, e.g. pex_binary(name="__workaround_pex_issue_2395", dependencies=["path/to#instructor", "path/to#pbipy"], ...)
2. run pants --no-local-cache package path/to:__workaround_pex_issue_2395 in CI before all other package
The --no-local-cache will force this to always execute the underlying pex ... command that will pre-seed the internal named cache on this machine, even though that can typically be served from cache. (the "local cache" there is referring to caching of exact process inputs and outputs, which is a different cache to the more flexible "named caches" here.)
The pants test :: workaround is something similar, and I suspect the occasional failures of that workaround are because all the PEX invocations are sometimes fully cached, and so don't run and thus don't seed the named cache. Having a targeted pex_binary will be much faster than forcing all tests to run without any caching at all.
Demonstration in https://github.com/calleo/pants-package-error/pull/1
(NB. if you're using remote caching, you'll probably need --no-remote-cache-read too. If you're using remote execution, this probably won't work.)incalculable-france-51377
04/09/2024, 1:15 PMincalculable-france-51377
04/09/2024, 1:46 PMcurved-television-6568
04/09/2024, 2:07 PMable-advantage-61346
04/09/2024, 2:14 PMbroad-processor-92400
04/14/2024, 11:30 PM[pex-cli]
version = "v2.3.1"
known_version = [
"v2.3.1|macos_arm64|71690e672871b55323f5d6ef9a3fe9705f1668662652c4081080e7ab27d44de3|4124530",
...
]
The hash and length are the sha256 hash and byte length of the pex artifact from https://github.com/pex-tool/pex/releases/tag/v2.3.1incalculable-france-51377
04/25/2024, 7:19 PM