1.下载miniconda
1.1下载:
官网下载
https://docs.conda.io/projects/miniconda/en/latest/
清华镜像下载:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/
1.2配置环境变量
设置里面搜索高级系统设置,打开环境变量,编辑path,新建三个环境变量




环境变量如下:
C:\Users\lenovo\miniconda3
C:\Users\lenovo\miniconda3\Scripts
C:\Users\lenovo\miniconda3\Library\bin
1.3换清华源
找到.condarc文件,一般该文件在目录C:\Users\用户名 路径下(我的电脑的用户名为lenovo)
用记事本打开.condarc文件,将里面内容修改为:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
2.配置虚拟环境
2.1 cmd 打开命令提示符,输入conda info -e查看当前python环境数目
我已经创建了三个python环境,base是miniconda自带的环境,geopy是我刚创建的新的环境
2.2 创建虚拟环境geo(删除用 conda remove -n 虚拟环境名字 --all)
C:\Users\lenovo>conda create -n geo python=3.10
继续看我们的python环境,已经有4个了
2.3 在geo虚拟环境下安装我所需要的包
切换到我的geo虚拟环境:activate geo(退出输入 deactivate)
在geo虚拟环境下安装一些常用的包
conda install -c conda-forge numpy pandas matplotlib
3.下载jupyter lab并实现jupyter lab下虚拟环境的使用
3.1 cmd 打开命令提示符,输入conda install -c conda-forge jupyter lab(下载jupyter lab)
conda install -c conda-forge jupyter lab
3.2 激活虚拟环境,在虚拟环境中下载ipykernel
activate 虚拟环境名字
conda install -c conda-forge ipykernel
3.3 将虚拟环境写入jupyter的kernel中
python -m ipykernel install --name 虚拟环境名 --display-name 虚拟环境名
3.4 在cmd命令行下使用jupyter lab
jupyter lab
3.5 右上角点击kernel然后修改kernel
可能出现的问题:
在安装完jupyter lab后,切换到虚拟环境kernel时,会出现无法import 已安装的包的问题,警告 No module named xxx。而在pycharm或者vscode中,却可以进行import。原因这个jupyter lab使用的python path是系统默认python path,而不是虚拟环境中的kernel。
解决办法是,手动在jupyter的kernel中写入虚拟环境的kernel
第一步:找到C:\Users\lenovo\miniconda3\share\jupyter\kernels文件夹,查看文件信息
发现只有一个python3文件,打开后发现一个kernel.json文件,用记事本继续打开kernel文件显示如下代码,圈红的第一行为python.exe的路径,圈红第二行为kernel显示的名字
第二步:发现只有一个kernel,我们手动建一个新的文件夹,将kernel的python.exe信息改为虚拟环境下的python.exe信息
将python3中的kernel.json文件复制到新建文件夹中,
将新文件夹下的kernel.json文件中的信息修改为虚拟环境下的python.exe,显示名字自定义修改