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)

相关推荐
老兵发新帖1 小时前
Ubuntu 上安装 Conda
linux·ubuntu·conda
一眼青苔4 小时前
python环境使用conda,conda如何升级默认的python版本
开发语言·python·conda
biter008812 小时前
ubuntu(28):ubuntu系统多版本conda和多版本cuda共存
linux·人工智能·ubuntu·conda
内网渗透12 小时前
Python 虚拟环境管理:venv 与 conda 的选择与配置
开发语言·python·conda·虚拟环境·venv
2501_9153743513 小时前
如何配置 Conda 使用镜像源加速
conda
2501_915374352 天前
使用 Conda 创建新环境
conda
Wiktok4 天前
Anaconda、conda和PyCharm在Python开发中各自扮演的角色
conda
nan_black8 天前
在Pycharm配置stable diffusion环境(使用conda虚拟环境)
stable diffusion·pycharm·conda
三劫散仙8 天前
pycharm无法识别到本地python的conda环境解决方法
python·pycharm·conda
hx_long9 天前
centos7 安装miniconda
python·conda