From 55441db68dc4f61e133713bdeaa3b569182e7a1a Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Mon, 27 Jan 2025 16:45:51 -0500 Subject: [PATCH] Modify install_prereqs to create a venv (#22477) Modify the macOS install_prereqs script used for Drake tarball installations to create a Python virtual environment in the location where Drake has been extracted. Also use this to install Drake's Python dependencies using PDM. Update user documentation accordingly. This means we are now using the pinned versions of our dependencies and are no longer keeping a duplicate copy of this list solely for installations. This also means that we are installing a pinned numpy in the venv for installations. This was already the case for source builds, but means we now no longer have any reason to install numpy from Homebrew, so remove it from there. --- doc/_pages/from_binary.md | 25 ++++++++++++++++++- setup/BUILD.bazel | 6 +++-- setup/mac/binary_distribution/Brewfile | 1 - .../binary_distribution/install_prereqs.sh | 7 +++++- .../mac/binary_distribution/requirements.txt | 11 -------- setup/python/pdm.lock | 2 +- setup/python/pyproject.toml | 4 +-- 7 files changed, 36 insertions(+), 20 deletions(-) delete mode 100644 setup/mac/binary_distribution/requirements.txt diff --git a/doc/_pages/from_binary.md b/doc/_pages/from_binary.md index 1773c90e4aac..d10959404522 100644 --- a/doc/_pages/from_binary.md +++ b/doc/_pages/from_binary.md @@ -66,6 +66,8 @@ Download the binary release ``*.tar.gz`` file, using one of the links above. In the example below, we'll use ``drake.tar.gz`` to refer to it, but your download will have a more version-specific filename. +#### Ubuntu + Create and activate the environment: ```bash @@ -77,11 +79,32 @@ source env/bin/activate Install dependencies within the environment: +```bash +sudo env/share/drake/setup/install_prereqs +```` + +Refer to [Quickstart](/installation.html#quickstart) for next steps. + +#### macOS + +Create the environment: + +```bash +mkdir -p env +tar -xvzf drake.tar.gz -C env --strip-components=1 +``` + +Install dependencies within the environment: + ```bash env/share/drake/setup/install_prereqs ```` -(On Ubuntu, the script might ask to be run under ``sudo``.) +Activate the environment: + +```bash +source env/bin/activate +``` Refer to [Quickstart](/installation.html#quickstart) for next steps. diff --git a/setup/BUILD.bazel b/setup/BUILD.bazel index 8e5fe09d8571..ab500a079e23 100644 --- a/setup/BUILD.bazel +++ b/setup/BUILD.bazel @@ -7,7 +7,6 @@ package(default_visibility = ["//visibility:public"]) # downstream projects. exports_files([ "mac/binary_distribution/Brewfile", - "mac/binary_distribution/requirements.txt", "mac/source_distribution/Brewfile", "mac/source_distribution/Brewfile-doc-only", "mac/source_distribution/Brewfile-maintainer-only", @@ -44,7 +43,9 @@ install_files( "//tools/cc_toolchain:apple": [ "mac/binary_distribution/Brewfile", "mac/binary_distribution/install_prereqs.sh", - "mac/binary_distribution/requirements.txt", + "python/pdm.lock", + "python/pyproject.toml", + "python/requirements.txt", ], "//tools/cc_toolchain:linux": [ "deepnote/install_nginx", @@ -58,6 +59,7 @@ install_files( strip_prefix = [ "mac/binary_distribution", "ubuntu/binary_distribution", + "python", ], rename = { "share/drake/setup/install_prereqs.sh": "install_prereqs", diff --git a/setup/mac/binary_distribution/Brewfile b/setup/mac/binary_distribution/Brewfile index 4468419d27ba..448f5ee570c1 100644 --- a/setup/mac/binary_distribution/Brewfile +++ b/setup/mac/binary_distribution/Brewfile @@ -8,7 +8,6 @@ brew 'gcc' brew 'fmt' brew 'glib' brew 'graphviz' -brew 'numpy' brew 'pkg-config' brew 'python@3.12' brew 'spdlog' diff --git a/setup/mac/binary_distribution/install_prereqs.sh b/setup/mac/binary_distribution/install_prereqs.sh index 2a90dcdf4f9c..21b36f768dc9 100755 --- a/setup/mac/binary_distribution/install_prereqs.sh +++ b/setup/mac/binary_distribution/install_prereqs.sh @@ -67,5 +67,10 @@ if ! command -v pip3.12 &>/dev/null; then fi if [[ "${with_python_dependencies}" -eq 1 ]]; then - pip3.12 install --break-system-packages -r "${BASH_SOURCE%/*}/requirements.txt" + readonly setup="${BASH_SOURCE%/*}" + readonly venv_root="$(cd "${setup}/../../.." && pwd)" + python3.12 -m venv "${venv_root}" + "${venv_root}/bin/pip3" install -U -r "${setup}/requirements.txt" + "${venv_root}/bin/pdm" use -p "${setup}" -f "${venv_root}" + "${venv_root}/bin/pdm" sync -p "${setup}" --prod fi diff --git a/setup/mac/binary_distribution/requirements.txt b/setup/mac/binary_distribution/requirements.txt deleted file mode 100644 index 08e81aad2b41..000000000000 --- a/setup/mac/binary_distribution/requirements.txt +++ /dev/null @@ -1,11 +0,0 @@ -# PyPI packages to install via pip for binary Drake distributions. - -# WARNING for Drake Developers: This list must be kept in sync with -# setup/python/pyproject.toml. - -ipywidgets -matplotlib -notebook -Pillow -pydot -PyYAML diff --git a/setup/python/pdm.lock b/setup/python/pdm.lock index d4baef4a7b9c..ec897ea3ae06 100644 --- a/setup/python/pdm.lock +++ b/setup/python/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "test", "wheel"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:5675c5bbfb85cb016da1228ab88e99c1eb08625a3c9374558a60844705872724" +content_hash = "sha256:b809d9d13dff5455d6d7ccd47bb4c93d97d5348781bceea33709393623b2d975" [[metadata.targets]] requires_python = ">=3.10" diff --git a/setup/python/pyproject.toml b/setup/python/pyproject.toml index 9a52c7749250..f145eb6fb5e2 100644 --- a/setup/python/pyproject.toml +++ b/setup/python/pyproject.toml @@ -15,13 +15,11 @@ name = "drake" requires-python = ">=3.10" # Dependencies needed to build Drake. -# -# WARNING for Drake Developers: This list must be kept in sync with -# setup/mac/binary_distribution/requirements.txt. dependencies = [ "ipywidgets", "matplotlib", "notebook", + "numpy", "Pillow", "pydot", "PyYAML",