From baea07a5e607dc1f89a250318d5f6688b5d3868f Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Mon, 20 Jan 2025 14:34:37 -0500 Subject: [PATCH] Modify install_prereqs to create a venv 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 f09980c47396..4a70781ce393 100644 --- a/setup/mac/binary_distribution/Brewfile +++ b/setup/mac/binary_distribution/Brewfile @@ -9,7 +9,6 @@ brew 'fmt' brew 'glib' brew 'graphviz' brew 'ipopt' -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 334ab2efeca3..a65631bc300d 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:6e0102fe5ea6c29e8888d56dfc6686fb1c73a2070f8dbff0e62ced5adb76a886" +content_hash = "sha256:100ca73d9872db129fe8024b21ae233953a204b3ffc7231ac35eb9cd1fca4fab" [[metadata.targets]] requires_python = ">=3.10" diff --git a/setup/python/pyproject.toml b/setup/python/pyproject.toml index ab21a4c64b07..76ed62db058c 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",