Miniconda安装使用(简单版)

因为之前重装了系统,很多软件设置需要恢复,特别是Python环境。最近小玩了一下Pyqt,接触到了Anaconda这个巨无霸软件

看了官网介绍它的用途,觉得完全用不到这么多功能,安装Anaconda后文件已经到达10G

再翻了翻发现还有个类似精简版的Miniconda,觉得可以用来管理虚拟环境

这篇文记录安装和使用过程


下载Miniconda

官网下载链接:https://docs.anaconda.com/free/miniconda/miniconda-other-installer-links/

本着稳定能用的优先原则,并考虑到之前编写的代码一直使用Python3.10版本,我选择这个版本

ScreenCaputure240308220008

注意:使用这个版本只是为了全局使用Python3.10,仍然可以通过指定高版本的Python创建虚拟环境,安装完成后可以通过命令conda search python 查看虚拟环境支持的版本


安装Miniconda

基本一路Next按钮,以下几个步骤需注意

  1. 安装类型,由于我的电脑叫PC,我选Just Me

    ScreenCaputure240308220726

  2. 虽然是Mini版本,但是安装完成后占用的磁盘空间还是挺大,选其他盘

    ScreenCaputure240308221015

  3. 高级选项

    1. 第一个复选框是创建开始菜单(觉得用处不大,保持默认)
    2. 第二个复选框是添加软件的环境变量,红字已经提示不推荐并列明了原因,也可以不勾后面自己手动去添加环境变量
    3. 第三个复选框是指定Python3.10为默认版本,相当于给电脑安装Python,所以如果在安装Miniconda前安装了Python,原先安装的就用不到了,可删;安装完成后Python的路径在minicoda3路径下;如果你不是这重装系统的情况,建议先把原来使用的全局环境或虚拟环境导出requirements.txt(pip freeze > requirements.txt),以便于恢复全局环境或虚拟环境

    ScreenCaputure240308221251


设置Miniconda

这是清华开源软件镜像站的一个网页,Anaconda 镜像使用帮助https://mirrors.tuna.tsinghua.edu.cn/help/anaconda/

我看了一下目前用不到这些内容,conda软件自带包管理(它本身就是管理),例如

1
2
3
4
5
6
7
8
9
安装包:
conda install package_name 安装满足依赖关系的最新版本的包
conda install package_name=x.x 安装指定版本的包
pip install netmiko==3.4.0 安装指定版本的包
pip install netmiko>=3.4.0 安装指定版本及以上的包

卸载包:
conda uninstall xxx,conda remove xxx
pip uninstall SomePackage

我还是习惯用pip命令,但是还是照着网页的说明操作了,也不知道为什么


基本使用

  1. 查看全局的Python版本和Python路径

    1
    2
    3
    4
    5
    6
    D:\>python -V
    Python 3.10.13

    D:\>where python
    D:\miniconda3\python.exe

    结果显示当前的Python版本是3.10.13,安装路径是D:\miniconda3\python.exe,以上输出表明安装完成

  2. 查看conda信息,命令:conda info

    ScreenCaputure240308225050

    结果显示 package cacheenvs directories的路径在 D:\miniconda3\, package cache是缓存已下载的包文件,envs directories是存放虚拟环境文件

  3. 创建一个名称为pyqt-base的虚拟环境(指定Python版本3.8,默认安装3.8的最高版本,也可以指定具体的版本如python=3.8.8)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    D:\>conda create -n pyqt-base python=3.8
    Channels:
    - defaults
    Platform: win-64
    Collecting package metadata (repodata.json): done
    Solving environment: done

    ## Package Plan ##

    environment location: D:\miniconda3\envs\pyqt-base

    added / updated specs:
    - python=3.8


    The following packages will be downloaded:

    package | build
    ---------------------------|-----------------
    ca-certificates-2023.12.12 | haa95532_0 127 KB defaults
    pip-23.3.1 | py38haa95532_0 2.8 MB defaults
    python-3.8.18 | h1aa4202_0 20.5 MB defaults
    setuptools-68.2.2 | py38haa95532_0 933 KB defaults
    sqlite-3.41.2 | h2bbff1b_0 894 KB defaults
    vc-14.2 | h21ff451_1 8 KB defaults
    wheel-0.41.2 | py38haa95532_0 126 KB defaults
    ------------------------------------------------------------
    Total: 25.3 MB

    The following NEW packages will be INSTALLED:

    ca-certificates anaconda/pkgs/main/win-64::ca-certificates-2023.12.12-haa95532_0
    libffi anaconda/pkgs/main/win-64::libffi-3.4.4-hd77b12b_0
    openssl anaconda/pkgs/main/win-64::openssl-3.0.13-h2bbff1b_0
    pip anaconda/pkgs/main/win-64::pip-23.3.1-py38haa95532_0
    python anaconda/pkgs/main/win-64::python-3.8.18-h1aa4202_0
    setuptools anaconda/pkgs/main/win-64::setuptools-68.2.2-py38haa95532_0
    sqlite anaconda/pkgs/main/win-64::sqlite-3.41.2-h2bbff1b_0
    vc anaconda/pkgs/main/win-64::vc-14.2-h21ff451_1
    vs2015_runtime anaconda/pkgs/main/win-64::vs2015_runtime-14.27.29016-h5e58377_2
    wheel anaconda/pkgs/main/win-64::wheel-0.41.2-py38haa95532_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 pyqt-base
    #
    # To deactivate an active environment, use
    #
    # $ conda deactivate


    D:\>

    命令:conda create -n pyqt-base python=3.8

  4. 虚拟环境查看

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    D:\>conda activate pyqt-base

    (pyqt-base) D:\>python -V
    Python 3.8.18

    (pyqt-base) D:\>pip list
    Package Version
    ---------- -------
    pip 23.3.1
    setuptools 68.2.2
    wheel 0.41.2

    (pyqt-base) D:\>

    结果显示Python版本为Python 3.8.18,已安装的包有三个,窗口的提示符行前面多了虚拟环境的名称。

  5. conda设置全局pip国内源

    1
    2
    3
    4
    5
    6
    7
    (pyqt-base) D:\>pip config set global.index-url  https://pypi.tuna.tsinghua.edu.cn/simple
    Writing to C:\Users\xxx\AppData\Roaming\pip\pip.ini

    (pyqt-base) D:\>pip config list
    global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'

    (pyqt-base) D:\>

    结果显示,在C盘的C:\Users\xxx\AppData\Roaming\pip\创建了一个pip.ini文件,查看配置可以看到对应配置

  6. 在虚拟环境下安装pyqt5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    (pyqt-base) D:\>pip install pyqt5
    Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
    Collecting pyqt5
    Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ca/ac/596e8ca16fd0634542d874c0d79219fc527ea7de73a5000092f60ecbf6e9/PyQt5-5.15.10-cp37-abi3-win_amd64.whl (6.8 MB)
    ---------------------------------------- 6.8/6.8 MB 3.3 MB/s eta 0:00:00
    Collecting PyQt5-sip<13,>=12.13 (from pyqt5)
    Downloading https://pypi.tuna.tsinghua.edu.cn/packages/88/cd/dd21cdb92d053ca71c02c75ab7bd32874b82b33bef61d6d70b5d898e684b/PyQt5_sip-12.13.0-cp38-cp38-win_amd64.whl (78 kB)
    ---------------------------------------- 78.3/78.3 kB 189.0 kB/s eta 0:00:00
    Collecting PyQt5-Qt5>=5.15.2 (from pyqt5)
    Downloading https://pypi.tuna.tsinghua.edu.cn/packages/37/97/5d3b222b924fa2ed4c2488925155cd0b03fd5d09ee1cfcf7c553c11c9f66/PyQt5_Qt5-5.15.2-py3-none-win_amd64.whl (50.1 MB)
    ---------------------------------------- 50.1/50.1 MB 7.8 MB/s eta 0:00:00
    Installing collected packages: PyQt5-Qt5, PyQt5-sip, pyqt5
    Successfully installed PyQt5-Qt5-5.15.2 PyQt5-sip-12.13.0 pyqt5-5.15.10

    (pyqt-base) D:\>pip list
    Package Version
    ---------- -------
    pip 23.3.1
    PyQt5 5.15.10
    PyQt5-Qt5 5.15.2
    PyQt5-sip 12.13.0
    setuptools 68.2.2
    wheel 0.41.2

    (pyqt-base) D:\>

一些conda命令

Command Useage
conda create -n myenv sqlite | python=x.x Create an environment containing the package sqlite or python
conda remove -n myenv –all Remove all packages from environment myenv and the environment itself
conda env list List the Conda environments
conda clean –all Remove index cache, lock files, unused cache packages, tarballs, and logfiles
conda clean –i Remove index cache
conda clean –p Remove unused packages from writable package caches. WARNING: This does not check for packages installed using symlinks back to the package cache.
conda search xxx Search for packages and display
conda activate myenv To activate this environment
conda deactivate To deactivate an active environment
conda create -n env2 –clone path/to/file/env1 Create an environment (env2) as a clone of an existing environment (env1)
多子网分支的第3阶段分层DMVPN实验 使用floccus插件同步谷歌浏览器书签
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×