1> 下载Anaconda
mkdir Anaconda
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
2> 安装Anaconda
yum -y install bzip2.x86_64
bash Anaconda3-2020.02-Linux-x86_64.sh
3> 配置jupyter
① 设置密码
source ~/.bashrc
ipython # 进入ipython界面
from notebook.auth import passwd
passwd() # 记录sha1后面的密码
exit()
② 修改config文件
jupyter notebook --generate-config
vim /root/.jupyter/jupyter_notebook_config.py # 在文件的最后增加下面的配置文件
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'passwd' # 上一步记录的sha1后面的密码
c.NotebookApp.open_browser = False
c.NotebookApp.allow_remote_access = True
c.NotebookApp.allow_root = True
c.NotebookApp.port = 2010
c.NotebookApp.notebook_dir = '/data/jupyter' # jupyter默认路径
③ 在云服务器安全组中开放上面设置的端口号
vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2010 -j ACCEPT
systemctl restart iptables
④ 开启jupyter服务
jupyter notebook --ip=0.0.0.0 --no-browser --allow-root # 终端运行
nohup jupyter notebook --allow-root > jupyter.log 2>&1 & # 后台运行
4> jupyter开机自启动
vim /lib/systemd/system/jupyter.service
# jupyter.service
[Unit]
Description=jupyter notebook
After=network.target
[Service]
Tpye=forking
EnvironmentFile=/root/anaconda3/bin/jupyter-notebook # 安装目录
ExecStart=/root/anaconda3/bin/jupyter-notebook # 安装目录
ExecStop=/usr/bin/pkill jupyter-notebook
KillMode=process
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable jupyter.service
sudo systemctl start jupyter.service
5> 添加代码自动补全功能
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
pip install jupyter_nbextensions_configurator
Nbextensions 的选项中勾选 Hinterland
6> 切换中英文界面
# 修改LANG变量
vim /etc/locale.conf
LANG="zh_CN.UTF-8" # 中文界面
LANG="en_US.UTF-8" # 英文界面
重启Centos
7> matplotlib不能显示中文
① 确认系统字体
fc-list:lang=zh # 显示支持的中文字体
② 安装matplotlib字体支持
# 通过代码查找目录
import matplotlib
print(matplotlib.matplotlib_fname())
# /root/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
cd /root/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
wget https://slzxf.xiaomy.net/font/SimHei.ttf
③ 修改matplotlib配置文件
cd /root/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/
vi matplotlibrc
axes.unicode_minus : True
font.family : sans-serif
font.sans-serif : SimHei
④ 删除缓存
print(matplotlib.get_cachedir()) # /root/.cache/matplotlib
rm -rf ~/.cache/matplotlib