-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A uv Environment Is Not Compatible With pyo3 Out Of The Box #11006
Comments
I assume this is a duplicate of #6812 |
It's likely that PyO3 can fix this by updating |
Hi @mcmah309 - can you give me some more details on how to reproduce this? I'm not following this issue or the linked pyo3 one well enough to figure out what the actual steps are. I tried both maturin and standalone pyo3 and they seem to work fine. First, creating a venv in
Then if I deactivate that venv and make an empty crate in
(For completeness, my local system is the NixOS 24.05 arm64 live CD inside So I'd like to know exactly what you're running to build and what the error message you're getting is. |
#### base: bases/ubuntu/cuda.md ####
FROM nvidia/cuda:12.6.3-cudnn-devel-ubuntu24.04
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends --no-install-suggests ca-certificates \
&& update-ca-certificates
#### rust: dependent/apt/rust/nightly.md ####
# Based off: https://github.com/rust-lang/docker-rust/blob/9f287282d513a84cb7c7f38f197838f15d37b6a9/nightly/bookworm/slim/Dockerfile
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=nightly
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
libc6-dev \
wget \
; \
dpkgArch="$(dpkg --print-architecture)"; \
case "${dpkgArch##*-}" in \
amd64) rustArch='x86_64-unknown-linux-gnu'; rustupSha256='6aeece6993e902708983b209d04c0d1dbb14ebb405ddb87def578d41f920f56d' ;; \
armhf) rustArch='armv7-unknown-linux-gnueabihf'; rustupSha256='3c4114923305f1cd3b96ce3454e9e549ad4aa7c07c03aec73d1a785e98388bed' ;; \
arm64) rustArch='aarch64-unknown-linux-gnu'; rustupSha256='1cffbf51e63e634c746f741de50649bbbcbd9dbe1de363c9ecef64e278dba2b2' ;; \
i386) rustArch='i686-unknown-linux-gnu'; rustupSha256='0a6bed6e9f21192a51f83977716466895706059afb880500ff1d0e751ada5237' ;; \
ppc64el) rustArch='powerpc64le-unknown-linux-gnu'; rustupSha256='079430f58ad4da1d1f4f5f2f0bd321422373213246a93b3ddb53dad627f5aa38' ;; \
s390x) rustArch='s390x-unknown-linux-gnu'; rustupSha256='e7f89da453c8ce5771c28279d1a01d5e83541d420695c74ec81a7ec5d287c51c' ;; \
*) echo >&2 "unsupported architecture: ${dpkgArch}"; exit 1 ;; \
esac; \
url="https://static.rust-lang.org/rustup/archive/1.27.1/${rustArch}/rustup-init"; \
wget "$url"; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version; \
apt-get remove -y --auto-remove \
wget \
;
# Make sure to remove trailing `\` when you copy over a new version.
# rm -rf /var/lib/apt/lists/*;
#### rust_essentials: dependent/apt/rust/essentials.md ####
# libssl-dev: Needed for openssl certificates (may need to add the pkg files to PKG_CONFIG_PATH)
# libasound2-dev: Needed for alsa (may need to add the pkg files to PKG_CONFIG_PATH)
# pkg-config: Quering local libraries for compilation. Needed by rustc.
RUN apt-get update && apt install -y libssl-dev libasound2-dev pkg-config
#### rust_components: dependent/rust/components.md ####
RUN rustup component add rustfmt
#### uv: dependent/apt/python/uv.md ####
RUN apt install -y build-essential libssl-dev pkg-config curl \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& . $HOME/.local/bin/env \
&& uv tool install mypy
#### ~INLINE~ ####
ENTRYPOINT ["/bin/bash"] (may want to change the base image to Basically just follow exactly what included below. The comment I linked to is a way to resolve the issues that happen with
|
Oh, I see now - I can reproduce the problem by building a binary that uses Python as a library: cargo init b
cd b
echo 'pyo3 = { version = "0.23" }' >> Cargo.toml
uv venv -p 3.12
. .venv/bin/activate
cat > src/main.rs << EOF
use pyo3::prelude::*;
fn main() {
Python::with_gil(|_py| ());
}
EOF
cargo run which gets me
And I see now why you had test cases, I think the right way to solve this is by adding an rpath to the link arguments. I'm not yet sure whether that belongs on our side or on pyo3's side, let me read a bit. Thanks for the details! |
Summary
It seems a uv environment is not compatible with pyo3 as
libpython
is not found for the active environment, nor is the python codec.PyO3/pyo3#4813 (comment)
Additionally the
.cargo/config.toml
needs to includeExample
Setup:
uv venv .venv --python 3.12 . .venv/bin/activate
src/lib.rs
Cargo.toml
The text was updated successfully, but these errors were encountered: