bash执行脚本 CondaError: Run ‘conda init‘ before ‘conda activate‘

执行脚本:

bash 复制代码
conda activate PaddleImageOcr && nohup paddlex --serve --port 8080 --pipeline OCR --device cpu --use_hpip True --save_path /tmp/PaddleImageOcr > paddleImageOcr.log 2>&1 &

提示CondaError: Run 'conda init' before 'conda activate' 错误。

要解决 CondaError: Run 'conda init' before 'conda activate' 错误,需要确保 Conda 在当前的 Shell 会话中已正确初始化。以下是具体步骤:

解决方法:

  1. 手动初始化 Conda(如果尚未初始化)

    bash 复制代码
    conda init bash

    执行后,关闭并重新打开终端,或使用 source 命令使配置生效:

    bash 复制代码
    source ~/.bashrc
  2. 在命令中显式初始化 Conda 环境 (推荐直接解决当前问题):

    conda activate 前添加 eval "$(conda shell.bash hook)",确保 Conda 环境在当前 Shell 生效:

    bash 复制代码
    eval "$(conda shell.bash hook)" && conda activate PaddleImageOcr && nohup paddlex --serve --port 8080 --pipeline OCR --device cpu --use_hpip True --save_path /tmp/PaddleImageOcr > paddleImageOcr.log 2>&1 &

完整修正后的命令:

bash 复制代码
eval "$(conda shell.bash hook)" && \
conda activate PaddleImageOcr && \
nohup paddlex --serve --port 8080 --pipeline OCR --device cpu --use_hpip True --save_path /tmp/PaddleImageOcr > paddleImageOcr.log 2>&1 &

关键说明:

  • eval "$(conda shell.bash hook)" :显式初始化当前 Shell 的 Conda 环境,绕过 conda init 的持久化配置要求。
  • 适用 Shell :如果使用 zsh 或其他 Shell,将 bash 替换为对应的 Shell 名称(如 conda shell.zsh hook)。
  • 环境存在性 :确保 PaddleImageOcr 环境已通过 conda create -n PaddleImageOcr 创建。

执行修正后的命令即可正常激活环境并启动服务。

相关推荐
tntxia1 天前
linux curl命令详解_curl详解
linux
扛枪的书生1 天前
Linux 网络管理器用法速查
linux
顺风尿一寸1 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode2 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫2 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
AlfredZhao3 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
戴为沐5 天前
Linux内存扩容指南
linux
zylyehuo5 天前
Linux 彻底且安全地删除文件
linux
用户805533698035 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
用户034095297916 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux