docker - Docker 镜像上的 pip 找不到 Rust - 即使安装了 Rust

标签 docker rust pip docker-build huggingface-tokenizers

我正在尝试安装一些 Python 包,即来自 Huggingface transformerstokenizers,它显然需要 Rust。所以我在我的 Docker 版本上安装 Rust:

FROM nikolaik/python-nodejs
USER pn
WORKDIR /home/pn/app

COPY . /home/pn/app/
RUN ls -la /home/pn/app/*
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

ENV PATH ~/.cargo/bin:$PATH

# Install Python dependencies.
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN python load_model.py

# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 4 --threads 4 app:app

但是,在安装分词器时,pip 似乎找不到 Rust:

Building wheels for collected packages: tokenizers
#11 103.2   Building wheel for tokenizers (pyproject.toml): started
#11 104.6   Building wheel for tokenizers (pyproject.toml): finished with status 'error'
#11 104.6   error: subprocess-exited-with-error
#11 104.6
#11 104.6   × Building wheel for tokenizers (pyproject.toml) did not run successfully.
#11 104.6   │ exit code: 1
#11 104.6   ╰─> [51 lines of output]
...
  error: can't find Rust compiler
#11 104.6
#11 104.6       If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.

为什么会发生这种情况?我如何确保 Rust 可用?

最佳答案

安装程序似乎在您的 .bashrc 文件中添加了一行来设置路径。 .bashrc 仅当您处于交互式 shell 中时才会运行,而当您运行构建脚本时则不会。因此,您的路径未设置为包含 Rust 编译器的目录。

据我所知,编译器安装在$HOME/.cargo/bin中。在您的情况下,这将是 /home/pn/.cargo/bin。要将其添加到路径中,您可以将 ENV 行添加到 Dockerfile 中,如下所示

FROM nikolaik/python-nodejs
USER pn
WORKDIR /home/pn/app

COPY . /home/pn/app/
RUN ls -la /home/pn/app/*
RUN curl --proto '=https' --tlsv1.2 -sSf -y https://sh.rustup.rs | sh
ENV PATH /home/pn/.cargo/bin:$PATH

# Install Python dependencies.
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
RUN python load_model.py

# to be equal to the cores available.
CMD exec gunicorn --bind :$PORT --workers 4 --threads 4 app:app

如果这不起作用,请尝试使用以下命令在镜像中运行 shell

docker run --rm -it <image name> bash

然后你可以四处寻找并尝试找到 rust 编译器的安装目录。

关于docker - Docker 镜像上的 pip 找不到 Rust - 即使安装了 Rust,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71895950/

相关文章:

python - 数组的所有排列,其中数组中的每个元素必须按0到n之间的范围递增

python - 在 mac (Big Sur) 上导入模块的问题,以及 sys.executable 和包的位置不匹配?

python - 如何安装这个轮子?

docker - 让 TeamCity 在 Docker 上运行

c# - 从 Web Api .Net Core 容器连接到 MySQL 容器?如何获取IP地址?

rust - Rust `array.each` 参数中使用了哪种类型的指针?

python - 如何从虚拟环境中复制的 pipfile 安装依赖项?

linux - 为什么 SIGHUP 在 Alpine Docker 容器中的 busybox sh 上不起作用?

php - Laradock:如何启用/安装 php7 ldap 支持扩展?

rust - Rust 是否有用于创建带有附加元素的数组的语法糖?