Ubuntu 安装 Python 环境管理工具 Miniconda 3

文章目录

    注意,推荐 为了避免律师函警告,从 miniconda 切换到 miniforge

    救命稻草 Miniconda

    不用 Miniconda 不行了,最近测试一个 python 的人工语音合成模块给 Android App 使用,安装依赖之后,
    直接把 Rasa 的开发环境搞崩了。。。怎么重装都不行。

    再也不敢这样粗放地管理 Python 依赖了,还是老老实实地用上环境隔离吧。

    下载

    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    

    链接来自于:

    https://docs.conda.io/en/latest/miniconda.html

    安装

    > bash Miniconda3-latest-Linux-x86_64.sh
    

    用户协议的确认,需要耐心,慢慢点击回车才能看到,输入 yes 即可。

    Do you accept the license terms? [yes|no]
    [no] >>> yes
    
    Miniconda3 will now be installed into this location:
    /home/zhongwei/miniconda3
    
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below
    
    [/home/zhongwei/miniconda3] >>>
    

    确认安装成功

    需要退出 shell,重新进入:

    > conda --version
    conda 25.1.1
    

    禁止 conda base 默认启用

    再次进入 shell,会发现默认启用了 conda base 环境,而我并不需要,因为偶尔才用到 python

    conda config --set auto_activate_base false
    

    退出

    conda deactivate
    

    新建环境

    conda create -n my_new_env python=3.10
    

    激活环境

    conda activate my_new_env
    

    fish shell $PATH 变量

    如果安装后,没有找到 conda,大概率是 conda 的安装目录不在 $PATH 中,fish shell 中的设置方法:

    vim ~/.config/fish/config.fish
    
    set -U fish_user_paths /home/zhongwei/miniconda3/bin $fish_user_paths
    

    重新进入 fish shell 即可。

    CondaError: Run ‘conda init’ before ‘conda activate’

    如果使用的是 fish shell。

    遇到上面错误,执行:

    conda init --all
    

    这个命令会配置所有的 shell 包括 ‘bash’, ‘cmd.exe’, ‘fish’, ‘powershell’, ‘tcsh’, ‘xonsh’, ‘zsh’。

    然后,重启 fish shell 即可。

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式