jupyter notebook配置虚拟环境
查看 anaconda3 安装了哪些虚拟环境
conda env list 或 conda info -e 确认当前存在什么虚拟环境。
[rin]# conda env list
# conda environments:
#
/home/ji/software/Anaconda/
base * /home/software/anaconda3
py38 /home/software/anaconda3/envs/py38
/home/sg/anaconda3
/home/sg/anaconda3/envs/LncDeep
/home/sg/anaconda3/envs/NCResNetEnv
/home/sg/anaconda3/envs/PLEK2
/home/sg/anaconda3/envs/py385
/home/sg/anaconda3/envs/py385_2110
/home/sg/anaconda3/envs/tens
/home/user01/anaconda3/envs/RL
创建 anaconda3 虚拟环境
cd /home/sqxiong/anaconda3/bin
conda create -n decode python=3.8.5
# To activate this environment, use
#
# $ conda activate decode
#
# To deactivate an active environment, use
#
# $ conda deactivate
删除移除 anaconda3 虚拟环境
# 第一步:首先退出环境
conda deactivate
# 第二步:查看虚拟环境列表,此时出现列表的同时还会显示其所在路径
conda env list
# 第三步:删除环境
conda env remove -p 要删除的虚拟环境路径
conda env remove -p /home/software/anaconda3/envs/decode
在特定虚拟环境下安装包
conda create -n mydlenv python=3.8.5
#
# To activate this environment, use
#
# $ conda activate mydlenv
#
# To deactivate an active environment, use
#
# $ conda deactivate
conda activate mydlenv ## 激活虚拟环境
which pip # 查看pip
/home/software/anaconda3/envs/mydlenv/bin/pip
安装包
# pip install wget
conda install -n your_env_name [package]对虚拟环境中安装额外的包
查看包的安装位置
# find ./ -name *wget*
./lib/python3.8/site-packages/wget.py
./lib/python3.8/site-packages/wget-3.2.dist-info
./lib/python3.8/site-packages/__pycache__/wget.cpython-38.pyc
/home/software/anaconda3/envs/mydlenv/lib/python3.8/site-packages
========================================================================================
为jupyter notebook配置虚拟环境
新安装好的虚拟环境,只有一个 Python 3
查看Jupyter Notebook 当前运行的虚拟环境
import os, sys
print(sys.executable) #
print(sys.version)
print(sys.version_info)
# which jupyter
/home/user01/anaconda3/bin/jupyter
# jupyter kernelspec list
Available kernels:
python3 /home/user01/anaconda3/share/jupyter/kernels/python3
【可行】为了让Jupyter Notebook支持虚拟运行环境,需要在Anaconda里安装一个插件。
1)退出目前正在运行的Jupyter Notebook Server
2)激活某个要用的虚拟环境: conda activate mydlenv
3)conda install nb_conda ### 必须
4)再重新开启 Jupyter Notebook
激活虚拟环境 mydlenv 之后做以下操作:
conda install -n mydlenv ipykernel ### 必须
# pip install ipykernel ipython ### 必须
# python -m ipykernel install --user --name mydlenv --display-name "mydlenv" ### 必须
重启
(mydlenv) [n]# nohup /home/software/anaconda3/bin/jupyter notebook --allow-root --notebook-dir='/data/pigenhancer/' --ip 0.0.0.0 > /home/software/anaconda3/bin/jupyter.log 2>&1
重启 浏览器。
/home/software/anaconda3/envs/mydlenv/bin
(mydlenv) []# pwd
/home/software/anaconda3/envs/mydlenv/bin
(mydlenv) ]# which python
/home/software/anaconda3/envs/mydlenv/bin/python
(mydlenv) []# nohup python -m jupyter notebook --allow-root --notebook-dir='/data/pigenhancer/' --ip 0.0.0.0 > /home/software/anaconda3/bin/jupyter.log 2>&1
(mydlenv) []# more /home/software/anaconda3/bin/jupyter.log
nohup: 忽略输入
/home/software/anaconda3/envs/mydlenv/bin/python: No module named jupyter
把已经添加成功的虚拟环境删除,可以先激活想要删除的虚拟环境,
然后输入:
jupyter kernelspec remove 虚拟环境名称
import os, sys
print(sys.executable) #
print(sys.version)
print(sys.version_info)
REF
https://www.cnblogs.com/emanlee/p/16126950.html
http://www.manongjc.com/detail/51-aovrpyptycuxsqv.html
https://zhuanlan.zhihu.com/p/409063952