码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • linux将miniconda移去其它位置


    linux 机上将 miniconda 的文件夹从 /data/itom/miniconda3 移去 /share/itom/miniconda3:

    mv /data/itom/miniconda3 /share/itom/
    
    • 1

    之后需要改一系列路径,参考 [1]。因为要改多个文件,遂写个脚本批量改。

    ~/.bashrc

    ~/.bashrc 中 conda 写入的初始化命令带路径,形如:

    unset CONDA_AUTO_ACTIVATE_BASE
    # >>> conda initialize >>>
    # !! Contents within this block are managed by 'conda init' !!
    __conda_setup="$('/data/itom/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$__conda_setup"
    else
        if [ -f "/data/itom/miniconda3/etc/profile.d/conda.sh" ]; then
            . "/data/itom/miniconda3/etc/profile.d/conda.sh"
        else
            export PATH="/data/itom/miniconda3/bin:$PATH"
        fi
    fi
    unset __conda_setup
    # <<< conda initialize <<<
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    路径前缀全改成新位置。

    miniconda3/

    miniconda 安装目录下(本例即新位置 /share/itom/miniconda3/)有几个子目录下的文件带路径:

    miniconda3/
    |- condabin/
    |  `- conda
    |- etc/profile.d/
    |  |- conda.csh
    |  `- conda.sh
    |- bin/
    |  |- 2to3-3.10          # 脚本
    |  |- bunzip2            # 二进制文件
    |  |- clear
    |  |- ...
    `- envs//bin/  # 各虚拟环境
       |- 2to3-3.10          # 脚本
       |- bunzip2            # 二进制文件
       |- clear
       |- ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    前两个路径下只有一两个文件,可以手动改;而 bin/ 下则有很多,且有些是脚本(文本)、有些是二进制文件;虚拟环境的 bin 目录 envs//bin/ 与 bin/ 一样,也有多个文件需要改。可以用 file 命令判断文件类型[2],如 file 2to3-3.10:

    2to3-3.10: Python script, ASCII text executable
    
    • 1

    而 file bunzip2:

    bunzip2: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped
    
    • 1

    只能改那些文本型的文件,脚本:

    • 类型中出现 ASCII text 就是文本。脚本第一行形如:#!/data/itom/miniconda3/bin/python。
    • 用 sed 替换,sed 中写正则时,路径中的 / 要转义,写成 \/。
    #!/bin/bash
    # update-conda-path.sh
    
    OLD_PREFIX=/data/itom/miniconda3  # 旧位置
    NEW_PREFIX=/share/itom/miniconda3 # 新位置
    P=$NEW_PREFIX/bin
    # P=$NEW_PREFIX/envs/cu110_pt171/bin # 虚拟环境的 bin/
    
    for f in `ls $P`; do
    	type_info=`file -b $P/$f`
    	if [[ $type_info == *"ASCII text"* ]]; then # 是文本
    		first_row=`cat $P/$f | head -n 1`
    		if [[ $first_row == *"$OLD_PREFIX"* ]]; then # 首行出现(旧)路经前缀
    			# echo $first_row
    			echo $P/$f
    			sed -i "s/\/data\/itom\/miniconda3/\/share\/itom\/miniconda3/g" $P/$f # 注意转义:\/
    		fi
    	fi
    done
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    clear

    miniconda3/bin/ 下也有个 clear,且默认用的是它(因为 conda 将自己放在 PATH 最前),移动之后用之会报错:

    terminals database is inaccessible
    
    • 1

    参考 [5],将 conda 的 clear 换个名,避免冲突:

    cd /share/itom/miniconda3 # 新位置
    mv bin/clear bin/clear.bak
    # 虚拟环境
    for e in `ls envs`; do
        mv envs/$e/bin/clear envs/$e/bin/clear.bak
    done
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    References

    1. 解决在linux移动anaconda到其他文件夹,conda: command not found的问题
    2. file command in Linux with examples
    3. How can I detect if a file is binary (non-text) in Python?
    4. How to check if a string contains a substring in Bash
    5. clear command - terminals database is inaccessible
  • 相关阅读:
    解决 react 项目启动端口冲突
    多 bit 数据流传输&FIFO-跨时钟域处理(2)
    设计模式:UML类图
    基于matlab的复杂背景下不规则目标边缘提取算法的仿真
    C#,数值计算——插值和外推,Laplace_interp的计算方法与源程序
    仅仅三行JAVA代码计算多边形的几何中心点
    【STM32教程】第二章 通用输入输出口GPIO
    WEB API学习笔记1
    YOLOv8优化策略:轻量级Backbone改进 | VanillaNet极简神经网络模型 | 华为诺亚2023
    电气无线测温系统在设备监测中的作用
  • 原文地址:https://blog.csdn.net/HackerTom/article/details/133677917
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号