美文网首页
Using Miniconda Python

Using Miniconda Python

作者: 华阳_3bcf | 来源:发表于2023-11-21 15:39 被阅读0次

    Miniconda 是一个轻量级的 Anaconda 版本,它是 Anaconda 的一个最小安装,仅包含 Conda 包管理器和 Python 解释器。

    功能类似 pipenv,方便使用不同版本的 python,学习成本也比较低。

    安装

    Miniconda — miniconda documentation

    conda on WSL (官方文档安装在了用户家目录下 ~/miniconda3, 我安装在了 /opt/miniconda3 目录下)

    $ sudo mkdir -p /opt/miniconda3
    $ cd /opt
    $ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ./miniconda3/miniconda.sh
    $ bash ./miniconda3/miniconda.sh -b -u -p ./miniconda3
    PREFIX=/opt/miniconda3
    Unpacking payload ...
    
    Installing base environment...
    
    
    Downloading and Extracting Packages
    
    
    Downloading and Extracting Packages
    
    Preparing transaction: done
    Executing transaction: done
    installation finished.
    $ /opt/miniconda3/bin/conda init zsh
    no change     /opt/miniconda3/condabin/conda
    no change     /opt/miniconda3/bin/conda
    no change     /opt/miniconda3/bin/conda-env
    no change     /opt/miniconda3/bin/activate
    no change     /opt/miniconda3/bin/deactivate
    no change     /opt/miniconda3/etc/profile.d/conda.sh
    no change     /opt/miniconda3/etc/fish/conf.d/conda.fish
    no change     /opt/miniconda3/shell/condabin/Conda.psm1
    no change     /opt/miniconda3/shell/condabin/conda-hook.ps1
    no change     /opt/miniconda3/lib/python3.11/site-packages/xontrib/conda.xsh
    no change     /opt/miniconda3/etc/profile.d/conda.csh
    modified      /home/edaizen/.zshrc
    
    ==> For changes to take effect, close and re-open your current shell. <==
    
    

    重新登录WSL,检查conda 安装的版本

    $ conda --version
    conda 23.10.0
    (base)
    $ conda env list
    # conda environments:
    #
    base                  *  /opt/miniconda3
    
    (base)
    

    Creating Conda Environments

    核心命令

    conda create -n <env_name> python=<version>
    

    例子,python=3.10以上

    $ conda create -n chatglm3-demo python=3.10
    Channels:
     - defaults
    Platform: linux-64
    Collecting package metadata (repodata.json): done
    Solving environment: done
    
    ## Package Plan ##
    
      environment location: /opt/miniconda3/envs/chatglm3-demo
    
      added / updated specs:
        - python=3.10
    
    
    The following packages will be downloaded:
    
        package                    |            build
        ---------------------------|-----------------
        pip-23.3                   |  py310h06a4308_0         2.7 MB
        python-3.10.13             |       h955ad1f_0        26.8 MB
        setuptools-68.0.0          |  py310h06a4308_0         936 KB
        wheel-0.41.2               |  py310h06a4308_0         109 KB
        ------------------------------------------------------------
                                               Total:        30.5 MB
    
    The following NEW packages will be INSTALLED:
    
      _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
      _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu
      bzip2              pkgs/main/linux-64::bzip2-1.0.8-h7b6447c_0
      ca-certificates    pkgs/main/linux-64::ca-certificates-2023.08.22-h06a4308_0
      ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.38-h1181459_1
      libffi             pkgs/main/linux-64::libffi-3.4.4-h6a678d5_0
      libgcc-ng          pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1
      libgomp            pkgs/main/linux-64::libgomp-11.2.0-h1234567_1
      libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1
      libuuid            pkgs/main/linux-64::libuuid-1.41.5-h5eee18b_0
      ncurses            pkgs/main/linux-64::ncurses-6.4-h6a678d5_0
      openssl            pkgs/main/linux-64::openssl-3.0.12-h7f8727e_0
      pip                pkgs/main/linux-64::pip-23.3-py310h06a4308_0
      python             pkgs/main/linux-64::python-3.10.13-h955ad1f_0
      readline           pkgs/main/linux-64::readline-8.2-h5eee18b_0
      setuptools         pkgs/main/linux-64::setuptools-68.0.0-py310h06a4308_0
      sqlite             pkgs/main/linux-64::sqlite-3.41.2-h5eee18b_0
      tk                 pkgs/main/linux-64::tk-8.6.12-h1ccaba5_0
      tzdata             pkgs/main/noarch::tzdata-2023c-h04d1e81_0
      wheel              pkgs/main/linux-64::wheel-0.41.2-py310h06a4308_0
      xz                 pkgs/main/linux-64::xz-5.4.2-h5eee18b_0
      zlib               pkgs/main/linux-64::zlib-1.2.13-h5eee18b_0
    
    
    Proceed ([y]/n)? y
    
    
    Downloading and Extracting Packages:
    
    Preparing transaction: done
    Verifying transaction: done
    Executing transaction: done
    #
    # To activate this environment, use
    #
    #     $ conda activate chatglm3-demo
    #
    # To deactivate an active environment, use
    #
    #     $ conda deactivate
    
    (base)
    
    

    验证

    检查不同环境下的 python 版本。

    $ which python
    /usr/bin/python    # 系统自带版本
    $ conda env list
    # conda environments:
    #
    base                     /opt/miniconda3
    chatglm3-demo            /opt/miniconda3/envs/chatglm3-demo
    
    
    $ conda activate chatglm3-demo
    (chatglm3-demo)
    $ python --version
    Python 3.10.13
    (chatglm3-demo)
    $ which python
    /opt/miniconda3/envs/chatglm3-demo/bin/python
    (chatglm3-demo)
    
    
    
    $ conda activate base
    (base)
    $ python --version
    Python 3.11.5
    (base)
    $ which python
    /opt/miniconda3/bin/python
    (base)
    
    $ conda deactivate  # 退出 base 环境,退到了上一个环境 chatglm3-demo
    (chatglm3-demo)
    $ conda deactivate  # 再来一次, 从 base 环境退出,回到了没有 conda 配置的环境
    
    # 删除一个环境
    $ conda env remove -n chatglm3-demo
    
    Remove all packages in environment /opt/miniconda3/envs/chatglm3-demo:
    

    Useful Miniconda Commands

    Obtain help on using conda with conda -h or `conda -h.

    $ conda config ⟸ Creates a ~/.condarc file the first time it is run.
    $ conda config --show-sources ⟸ Shows the channels that provide the packages.
    $ conda info ⟸ Display information about current conda install.
    $ conda env list ⟸ Lists your conda environments.
    $ conda list ⟸ Lists installed Python modules.
    $ conda list --export ⟸ Save package list for future use.
    $ conda clean -all ⟸ Remove cache files.

    相关文章

      网友评论

          本文标题:Using Miniconda Python

          本文链接:https://www.haomeiwen.com/subject/kjnbwdtx.html