Pycharm安装并配置jupyter notebook
Pycharm安装并配置jupyter notebook
一: 安装命令jupyter: pip install jupyter
如果缺少依赖,缺啥装啥
二: 运行 jupyter notebook
- 首先,查看一下自己是否已经安装成功,在终端输入:
jupyter notebook
如果运行成功,结果如下:
[I 09:03:15.177 NotebookApp] JupyterLab beta preview extension loaded from /home/winddy/anaconda3/lib/python3.6/site-packages/jupyterlab [I 09:03:15.177 NotebookApp] JupyterLab application directory is /home/winddy/anaconda3/share/jupyter/lab [I 09:03:15.182 NotebookApp] Serving notebooks from local directory: /home/winddy [I 09:03:15.182 NotebookApp] 0 active kernels [I 09:03:15.182 NotebookApp] The Jupyter Notebook is running at: [I 09:03:15.182 NotebookApp] http://localhost:8888/?token=c19f036f3beb2bce5112ca9c2f4565e738175a9853302e44 [I 09:03:15.182 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 09:03:15.183 NotebookApp] Copy/paste this URL into your browser when you connect for the first time, to login with a token: http://localhost:8888/?token=c19f036f3beb2bce5112ca9c2f4565e738175a9853302e44&token=c19f036f3beb2bce5112ca9c2f4565e738175a9853302e44 [I 09:03:15.693 NotebookApp] Accepting one-time-token-authenticated connection from ::1 Created new window in existing browser session. [W 09:03:16.282 NotebookApp] Error stat-ing /home/winddy/.gvfs: [Errno 13] Permission denied: '/home/winddy/.gvfs'
从上面可以知道,Jupyter notebook 生成的服务器地址为:http://localhost:8888/?token=c19f036f3beb2bce5112ca9c2f4565e738175a9853302e44 其中端口号为8888,注意,如果你打开多个Jupyter notebook , 那么每一个服务的端口号是不一样的
三: 上面都执行成功后,在pycharm 配置 jupyter notebook
这里巨坑,pycharm 的官网都JB坑
先给无差错的配置结果
-
在pycharm 新建一个后缀名为:.ipynb 的文件,如果你的pycharm没有解析改后缀名的插件,按照提示默认装好插件就可以
-
在第一个cell中输入: %matplotlib inline
-
点击运行按钮,这时,用户会因为环境不同会报各种错,这个放在后面讲
-
点击后pycharm会弹出一个会话框
注意,你可以在这个会话框中填入服务器地址,但是,我们这里只想在本地编辑,所以直接点取消, 然后出现
他会说不能连接到Jupyter notebook, 我们不管这个提示,因为我们只想在本地编辑,所以直接点击 run Jupyter notebook
!!!!!!到这里,如果没出现错误的话,pycharm会直接帮你启动服务并运行你指定的代码
(如果,你看到这个界面,那说明就OJBK了)
-
填写测试代码,逐个运行
四: 常见错误
- 如下,报“ Running as root is not recommended. Use --allow-root to bypass.”, 这个比较好解决,这个错误的原因是你是以root身份运行pycharm。 所以我们只要退出pycharm,然后在pycharm所在目录下 运行指令
sh pycharm.sh
, 如果你是用命令:sudo sh pycharm.sh
运行pycharm,那么你就会以管理员的身份运行pycharm (注意,重启终端,如果你的终端刚被执行了sudo, 那么此时执行 sh pycharm.sh 也是管理员身份)
[I 09:02:18.636 NotebookApp] JupyterLab beta preview extension loaded from /home/winddy/anaconda3/lib/python3.6/site-packages/jupyterlab [I 09:02:18.636 NotebookApp] JupyterLab application directory is /home/winddy/anaconda3/share/jupyter/lab [C 09:02:18.641 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
- 报权限不够, 直接按提示路径找到 jupyter的文件夹,修改权限问任何人可读可写
sudo chmod 777 jupyter/
Permission denied: '/home/winddy/.local/share/jupyter/kernels'
- 报 _xsrf 参数丢失, 官方bug, 请下载最新版本
NotebookApp] '_xsrf' argument missing from POST
作者:winddy_akoky
链接:https://www.jianshu.com/p/3d2415de9dd8
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。