当前位置:   article > 正文

ubuntu-jupyter环境搭建_ubuntu下jupyter notebook

ubuntu下jupyter notebook

文档

使用pip安装jupter-notebook

pip3 install --upgrade pip更新你的pip

pip3 install notebook -i https://pypi.tuna.tsinghua.edu.cn/simple

运行jupter-notebook

jupyter notebook

生成配置文件

jupyter notebook --generate-config

在这里插入图片描述
会在家目录.jupyter中生成配置文件

指定端口

jupyter notebook --port 9999

打开特定的notebook

jupyter notebook notebook.ipynb

配置文件相关

配置远程访问

修改jupyter_notebook_config.py文件
c.NotebookApp.ip='localhost改为c.NotebookApp.ip='0.0.0.0'在防火墙允许8888端口的情况下,你可以通过局域网去访问

配置启动关闭浏览器

c.NotebookApp.open_browser = False

配置密码

在这里插入图片描述
根据说明,我们需要执行以上代码获取其加密的值,然后将其填入即可
在这里插入图片描述

一直开启服务器

使用screen即可
如果没有安装命令
sudo apt install screen

打开一个交互screen

screen -S notebook
然后开启notebook
jupyter notebook然后关闭窗口就行了

notebook补全

参考Jupyter Notebook 添加代码自动补全功能

pip3 install jupyter_contrib_nbextensions
关闭notebook后
jupyter contrib nbextension install --user --skip-running-check

启动 Jupyter Notebook,勾选设置
在这里插入图片描述
这个时候会报错
TypeError: __init__() got an unexpected keyword argument 'column'

参考Jupyter按tab键无法补全,而且报错TypeError: init() got an unexpected keyword argument ‘column‘的解决办法

在这里插入图片描述

pip3 install jedi==0.17 -i https://mirror.edu.cn/pypi/simple

然后就可以愉快补全了

在这里插入图片描述

vscode中使用

首先要在jupyter服务器的机子上修改token让vscode能够连接上内核
vim ~/.jupyter/jupyter_notebook_config.py
其中密码填入你想填入的值
在这里插入图片描述
然后在vscode中下载python插件
然后按下ctrl+shift+p进入命令查找,输入服务器

在这里插入图片描述

在这里插入图片描述

填入http://ip:port/?token=你填入的值即可

在python文件中使用符号#%%即可开启一个框格

在这里插入图片描述

转换为pdf

  1. pip3 install nbconvert
    然后在命令行中使用
    python3 -c "import nbconvert看一下是否可以导入
  2. 安装pandoc
    下载链接
    安装完后,如果还提醒没有找到pandoc,记得加入环境变量D:\pandoc
  3. 安装MiKTeX
    下载链接
    安装后,记得添加环境变量
    在这里插入图片描述
  4. 完成后,在命令行中使用
    jupyter nbconvert a.ipynb --to pdf --output a.pdf
    随便使用一个jupyter来进行转换,这个时候会弹出安装选项装一些依赖包,直接点击install即可,最好将左下角的取消框选,免得一直弹窗,最后等待一会,再次进行转换,转换成功后就可以在vscode里面进行转换了。
    在这里插入图片描述

权限问题

sudo jupyter notebook --allow-root

转换相关问题

使用html转换为pdf

sudo apt install Pyppeteer
然后在随便一个含有notebook的文件下执行
jupyter nbconvert --to webpdf --allow-chromium-download test.ipynb

这样你后面的notebook就都可以在网页上面进行转换了
请添加图片描述

更换主题

jupyter更换主题(win)
pip3 install --upgrade jupyterthemes
jt -t oceans16 -T

在vscode中用动图

pip install ipympl
嵌入
%matplotlib ipympl
或者
%matplotlib notebook

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/245020
推荐阅读
相关标签
  

闽ICP备14008679号