查看当前已经有哪些虚拟环境
conda env list
创建虚拟环境
conda create -n env_name python=版本号
激活虚拟环境
conda activate env_name
退出虚拟环境
conda deactivate
删除虚拟环境
conda remove -n env_name --all
jupyter notebook中安装虚拟环境
1.查看已有的kernel
jupyter kernelspec list
2.进入想添加的虚拟环境,添加kernel
conda install ipykernel
在jupyter中添加:
python -m ipykernel install --user --name env_name --display-name "env_name"
3.这时就可在jupyter中看到存在的虚拟环境了
4.删除kernel
jupyter kernelspec remove kernelname
在WSL环境中使用jupyter时的一些注意事项:
1.打开jupyter环境时输入:
jupyter notebook --ip=0.0.0.0 --allow-root
2.在退出jupyter时不要直接把浏览器关掉,要找见notebook的首页,点击Quit退出,否则只能退出五十六、重新进了。
jupyter notebook中安装插件
输入一下两行代码即可运行
pip install jupyter_contrib_nbextensions -i https://pypi.tuna.tsinghua.edu.cn/simple
jupyter contrib nbextension install --user
安装完毕,重启jupyter之后就行
复制虚拟环境
conda create -n conda-env2 --clone conda-env1
这里conda-env2是新创建的Conda环境,conda-env1是被复制的Conda环境,
复制完成后,两个环境的Python配置是完全相同的
conda-env1 也可以是环境的路径*(将这个电脑上的环境复制到另一个电脑上的时候)
导出某个虚拟环境,并进行打包:
# 导出虚拟环境
# env_name为需要克隆的虚拟环境名称
# 不加路径的话默认导出到当前路径下
conda env export -n env_name > 路径+environment.yaml
# 导入虚拟环境
# env_name 你准备创建的新的虚拟环境名称
conda env create -n env_name -f environment.yaml
更换虚拟环境中python的版本号
conda install python=3.6
修改jupyter的初始化路径
输入
jupyter notebook --generate-config
生成jupyter的配置文件
打开配置文件,找到
c.NotebookApp.notebook_dir = ''
引号内写明你想定义的初始化路径
修改完毕即可