我正在尝试安装一些 Python 包,即来自 Huggingface transformers
的 tokenizers
,它显然需要 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/