dockerfile 中激活conda并安装package

遇错的dockerfile写法:

bash 复制代码
WORKDIR /tmp
RUN wget "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh" -O ~/miniconda.sh \
    && bash ~/miniconda.sh -b -p $HOME/miniconda \
    && ~/miniconda/bin/conda init $(echo /bin/bash | awk -F '/' '{print $NF}')

RUN echo yes | $HOME/miniconda/bin/conda create -n textgen python=3.10.9 \
    && $HOME/miniconda/bin/conda activate textgen \
    && pip install git+https://github.com/huggingface/transformers.git@9eae4aa57650c1dbe1becd4e0979f6ad1e572ac0 \
    && pip install SentencePiece

遇到的错误:

bash 复制代码
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.

解决办法:

bash 复制代码
WORKDIR /tmp
RUN wget "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh" -O ~/miniconda.sh \
    && bash ~/miniconda.sh -b -p $HOME/miniconda \
    && ~/miniconda/bin/conda init bash
ENV PATH=/root/miniconda/bin:$PATH
RUN echo yes | conda create -n textgen python=3.10.9
SHELL ["conda", "run", "-n", "textgen", "/bin/bash", "-c"]
RUN python --version && pip install git+https://github.com/huggingface/transformers.git@9eae4aa57650c1dbe1becd4e0979f6ad1e572ac0 \
    && pip install SentencePiece
SHELL ["/bin/bash", "-c"]

参考:Activating a Conda environment in your Dockerfile (pythonspeed.com)

相关推荐
砍材农夫6 天前
python环境|conda安装和使用(1)
开发语言·后端·python·conda
匆匆整棹还6 天前
mamba的安装和版本对应
conda
2601_961875247 天前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
没有钱的钱仔8 天前
自动创建conda虚拟环境,并安装依赖包
conda
砍材农夫9 天前
python环境|pip|uv|venv|Conda区别
后端·python·conda·pip·uv
pixelpilot110 天前
Conda:跨平台的二进制包管理器
其他·conda
lg_cool_10 天前
使用conda管理python运行环境并关联vscode
vscode·python·conda
javajenius10 天前
Pixi:用 Rust 重写 Conda 体验的包管理工具
开发语言·其他·rust·conda
小白弄潮儿11 天前
Conda 使用入门指南
conda
DFT计算杂谈11 天前
WannierTools输入文件wt.in一键批量生成脚本
java·前端·chrome·python·算法·conda