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)

相关推荐
遥感之家2 天前
GEE+本地XGboot分类
conda
一个平凡的IT农民工4 天前
如何在window 使用 conda 环境下载大模型
conda·transformer
不断进步的咕咕怪4 天前
conda-pack迁移虚拟环境
conda
code_____monkey4 天前
conda 常见命令
linux·运维·conda
七月的和弦5 天前
Miniconda 安装与配置指南
python·conda
西柚小萌新5 天前
python--在服务器上面创建conda环境
服务器·python·conda
52Hertz_leona7 天前
在pycharm2024.3.1中配置anaconda3-2024-06环境
python·pycharm·conda
_刘文凯_7 天前
R环境配置 以及Debug方法 (VSCode, conda, 远程R)
vscode·r语言·conda
楚歌again9 天前
在 Windows 10 Conda 环境中安装 PyTorch 并配置 NVIDIA GeForce RTX 3060 GPU 的记录草稿
pytorch·windows·conda
Funing710 天前
终端中运行 conda install 命令后一直显示“Solving environment: \ ”
人工智能·vscode·python·深度学习·编辑器·conda