Anaconda+Pycharm专业版+Jupyter notebook


1 Anaconda中安装和配置Jupyter notebook

参考资料:https://www.cnblogs.com/wqbin/p/11996766.html

1.1 安装jupyter 

安装anaconda环境,激活环境:conda activate py37后,直接执行如下命令

conda install jupyter

1.2 配置jupyter

(1)前置条件:一个配置文件

第一步生成配置文件 jupyter_notebook_config.py

jupyter notebook --generate-config

注意:配置文件位于

 

 

(2)生成密码

第二步bash生成

jupyter notebook password
Enter password:  xxxx
Verify password: xxxx
[NotebookPasswordApp] Wrote hashed password to /home/rdev/jupyter/jupyter_notebook_config.json

(3)添加到配置文件

在对应文件夹中找到配置文件,将哈希密码添加到配置文件 jupyter_notebook_config.py

复制代码
# ip 设置为 *
c.NotebookApp.ip = '*'
# 密码 设置为 sha1 
c.NotebookApp.password = u'sha1:xxxxx:xxxxxxxxxxx<your hashed password here>'
# 浏览器设置不打开
c.NotebookApp.open_browser = False
# 设置一个固定的接口
c.NotebookApp.port = 8888
复制代码

1.3 在Pycharm中使用Jupyter

(1)启动Jupyter

在Pycharm的终端中输入:

jupyter notebook 

结果如下:说明启动成功。点击终端中的链接跳转到浏览器,输入密码即可在浏览器中使用Jupyter

 (2)使用Jupyter

在项目中新建ipynb文件

 然后点击配置Jupyter服务器,将上面Pycharm终端中的url复制到其中,在后面追加“?token=你的密码”

 

 

 (3)测试

#%%
 ​
 import numpy as np
 import matplotlib.pyplot as plt
 ​
 x=np.arange(0,2*np.pi,0.01)
 y=np.sin(x)
 ​
 plt.plot(x,y)
 plt.show()

2、Pycharm中更换Jupyter notebook背景

参考资料:https://blog.csdn.net/Apple_xiaoli/article/details/104533008

2.1 图表样式问题

测试后发现,对于图表样式,图表输出是白底,同时黑色字体会和背景融为一体,就像这样:

 

 解决方法:安装jupyterthemes

在conda中使用命令安装;

conda install jupyterthemes   

然后,在ipynb文件中添加如下代码:

from jupyterthemes import jtplot
jtplot.style()  # 使用当前主题样式进行图表背景填充

解决后的图表变为:

 2.2 更换主题

在conda中,安装jupyterthemes后,输入命令jt -l(这是list)可以查看主题

输入命令jt -t 主题名 可以使用该主题

 浏览器中jupyter效果如图,但是Pycharm中图表样式并没有改变

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM