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一下,不过有强迫症可以用一下脚本

相关推荐
山有木兮木有枝_16 分钟前
JavaScript 设计模式--单例模式
前端·javascript·代码规范
一大树30 分钟前
Vue3 开发必备:20 个实用技巧
前端·vue.js
颜渊呐35 分钟前
uniapp中APPwebview与网页的双向通信
前端·uni-app
10年前端老司机1 小时前
React 受控组件和非受控组件区别和使用场景
前端·javascript·react.js
夏晚星1 小时前
vue实现微信聊天emoji表情
前端·javascript
停止重构1 小时前
【方案】前端UI布局的绝技,响应式布局,多端适配
前端·网页布局·响应式布局·grid布局·网页适配多端
極光未晚1 小时前
TypeScript在前端项目中的那些事儿:不止于类型的守护者
前端·javascript·typescript
ze_juejin1 小时前
Vue3 + Vite + Ant Design Vue + Axios + Pinia 脚手架搭建
前端·vue.js
lichenyang4531 小时前
React项目(移动app)
前端
用户61848240219511 小时前
Vue-library-start,一个基于Vite的vue组件库开发模板
前端