conda环境迁移,修改conda路径(附带脚本)

方法1

  1. 现将文件夹移动到对应用户的~目录下(或其他目录)

    bash 复制代码
    mv /home/asushiro/miniconda3 /root/miniconda3
  2. 建立软链接
    然后创建软链接,相当于快捷方式

    bash 复制代码
    ln -s /root/miniconda3 /home/aushiro/miniconda3

方法2

将对应miniconda中的文件路径全部改掉

这里使用python脚本实现

主要需要改的地方是/.../miniconda3/bin/*以及/.../miniconda3/etc/profile.d/*中的全部文件

  1. 先修改 ~/.bashrc

    bash 复制代码
    vim ~/.bashrc

    添加上

    bash 复制代码
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/root/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/root/miniconda3/etc/profile.d/conda.sh" ]; then
            . "/root/miniconda3/etc/profile.d/conda.sh"
        else
            export PATH="/root/miniconda3/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
  2. 首先改bin目录里的
    将需要改的文件名输入到target.txt文件夹里

    shell 复制代码
    echo `ls` > ~/target.txt

    然后再~文件夹下创建modify.py
    内容为

    python 复制代码
    import os
    from tqdm import tqdm
    
    with open("./target.txt", 'r') as f:
        line = f.readline()
        file_name_total = list(map(str, line.split()))
        for file_name in tqdm(file_name_total):
            file_path = os.path.join("/root/miniconda3/bin/", file_name)
            try:
                with open(file_path, 'r', encoding="utf-8") as f:
                    content = f.read()
                content = content.replace("/home/asushiro", "/root")
                with open(file_path, 'w', encoding="utf-8") as f:
                    f.write(content)
            except UnicodeDecodeError:
                print("decode error")
                continue
  3. 同理然后进入etc/profile.d文件夹下

    shell 复制代码
    echo `ls` >~/target.txt

    运行modify.py

    python 复制代码
    import os
    from tqdm import tqdm
    
    with open("./target.txt", 'r') as f:
        line = f.readline()
        file_name_total = list(map(str, line.split()))
        for file_name in tqdm(file_name_total):
            file_path = os.path.join("/root/miniconda3/etc/profile.d/", file_name)
            try:
                with open(file_path, 'r', encoding="utf-8") as f:
                    content = f.read()
                content = content.replace("/home/asushiro", "/root")
                with open(file_path, 'w', encoding="utf-8") as f:
                    f.write(content)
            except UnicodeDecodeError:
                print("decode error")
                continue
  4. 最后刷新环境变量即可

    shell 复制代码
    source ~/.bashrc

如遇其他路径问题同理解决,最简单的是link一下,不过有强迫症可以用一下脚本

相关推荐
wangbing112515 分钟前
开发指南139-VUE里的高级糖块
前端·javascript·vue.js
半桶水专家34 分钟前
Vue 3 动态组件详解
前端·javascript·vue.js
csj5039 分钟前
前端基础之《React(6)—webpack简介-图片模块处理》
前端·react
我有一棵树39 分钟前
避免 JS 报错阻塞 Vue 组件渲染:以 window.jsbridge 和 el-tooltip 为例
前端·javascript·vue.js
Fanfffff72040 分钟前
前端样式局部作用域:从Scoped到CSS Modules 的完整指南
前端·css
前端大神之路41 分钟前
vue2 模版编译原理
前端
00后程序员张41 分钟前
Web 前端工具全流程指南 从开发到调试的完整生态体系
android·前端·ios·小程序·uni-app·iphone·webview
凌泽1 小时前
写了那么多年的代码,我开始写“规范”了:AI 驱动的开发范式革命
前端·vibecoding
没有鸡汤吃不下饭1 小时前
解决前端项目中大数据复杂列表场景的完美方案
前端·javascript·vue.js
旧雨散尘2 小时前
【react】react初学6-第一个react应用-待办事项
前端·react.js·前端框架