jupyter安装教程
1.jupyter notebook安装
1.1 本文档适用的情况
Windows10环境已安装WSL2下的Ubuntu20.04
WSL2
Ubuntu20.04
1.2 Jupyternotebook安装流程
PS:这里推荐安装jupyter notebook而非jupyter lab,
以下为安装步骤:
1 2 3
| pip install jupyter notebook
jupyter notebook --generate-config
|
这一步会生成一个jupyternotebook的配置文件文件位置在(如果是root用户登录):’/home/usrname/.jupyter/jupyter_notebook_config.py’
1
| jupyter notebook password
|
复制里面引号的哈希码,那个就是加密后的密码
设置你windows电脑的浏览器能打开jupyternotebook
创建软连接:
1
| sudo ln -sf /mnt/c/'Program Files \(x86\)'/Microsoft/Edge\ Dev/Application/msedge.exe /usr/bin/msedge
|
test: 终端里直接输入msedge能直接打开你的Windows的EDGE DEV浏览器
vim /root/.jupyter/jupyter_notebook_config.py
1 2 3 4 5 6 7 8
| c.ServerApp.ip = '' c.ServerApp.allow_remote_access = True c.ServerApp.allow_root = True c.ServerApp.notebook_dir = '/root/Projects' c.ServerApp.use_redirect_file = False c.ServerApp.password = '此处填写3-2-1步骤生成的password'
|
把Windows的EDGE DEV作为Ubuntu的默认浏览器,找到这行
1
| # c.ServerApp.browser = ''
|
不取消注释,在下面添加
1 2 3
| import webbrowser webbrowser.register('msedge',None,webbrowser.GenericBrowser('/usr/bin/msedge')) c.NotebookApp.browser='msedge'
|
2 多虚拟环境下jupyter notebook的配置
在这之前可以进行apt换源,pip换源的操作,详情BING搜一下就可以了。
这里不推荐安装virtualenvwrapper,一切为了降低学习成本,而且安装了jupyter notebook之后也不需要频繁激活虚拟环境。
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
| pip install virtualenv
# 在/root(这里笔者以root用户登录的)文件夹下新建一个Virtualevs的文件夹用来存放虚拟环境
mkdir /root/Virtualenvs cd /root/Virtualenvs
# 建立虚拟环境名字为‘tensorflow’
virtualenv -p /usr/bin/python3.8 tensorflow
# 激活虚拟环境配置jupyter notebook
source /root/Virtualenvs/tensorflow/bin/avtivate
# 这里终端应该是类似(tensorflow)...# 这种的形式,就说明进入到了虚拟环境,可以pip list查看一下安装的包,应该是 之后setuptools什么的
pip install ipykernel python -m ipykernel install --name tensorflow(这里是实际的虚拟环境的名字) --display-name tensorflow(这里是你想要显示的名字)
# 或下边这句
python -m ipykernel install --user
# 再打开jupyter notebook之后就可以在new那里看到新建的虚拟环境了
jupyter notebook
# 而且这样之后即使deactivate虚拟环境之后,在基础的那个环境里面打开jupyter notebook之后也可以选择虚拟环境
|
扩展安装
1 2 3
| pip install jupyter_contrib_nbextensions jupyter contrib nbextension install --user 这之后就可以看到Nbextension,复选框选择哪个就是激活哪个
|