2023-07-05 09:34:06 +08:00
|
|
|
# 工作环境
|
|
|
|
|
|
|
|
|
|
## 目录
|
|
|
|
|
|
2023-08-08 18:22:43 +08:00
|
|
|
`mkdir /data/jupyter && cd /data/jupyter`
|
2023-07-05 09:34:06 +08:00
|
|
|
|
|
|
|
|
# Conda
|
|
|
|
|
|
|
|
|
|
## 安装
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#下载最新版本
|
|
|
|
|
wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
|
|
|
|
|
chmod 777 Miniconda3-latest-Linux-x86_64.sh #给执行权限
|
|
|
|
|
bash Miniconda3-latest-Linux-x86_64.sh #运行
|
|
|
|
|
|
|
|
|
|
#环境变量生效
|
|
|
|
|
source ~/.bashrc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 配置
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#**更换清华镜像源**
|
|
|
|
|
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
|
|
|
|
|
conda config --set show\_channel\_urls yes
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
# Jupyter
|
|
|
|
|
|
|
|
|
|
## 安装
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#安装jupyter
|
|
|
|
|
conda install jupyter notebook
|
|
|
|
|
#创建环境
|
|
|
|
|
conda create -n py3 python=3.7
|
|
|
|
|
conda activate py3
|
|
|
|
|
conda install notebook ipykernel
|
|
|
|
|
python -m ipykernel install --user --name py3 --display-name="python3.7"
|
|
|
|
|
#退出环境
|
|
|
|
|
conda deactivate
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 配置
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#生成配置
|
|
|
|
|
jupyter notebook --generate-config
|
|
|
|
|
#修改配置
|
|
|
|
|
c.NotebookApp.notebook_dir = '/data/jupyter'
|
|
|
|
|
c.NotebookApp.ip = '*'
|
|
|
|
|
c.NotebookApp.allow_root = True
|
|
|
|
|
c.NotebookApp.open_browser = True
|
|
|
|
|
c.NotebookApp.password = u'sha1:4f96fe6d1725:2e8650de1b1b7dbae474c7de97b3b5484f2fe537' #输入上面加密后得到的密文
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## PIP
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
mkdir ~/.pip
|
|
|
|
|
%%writefile ~/.pip/pip.conf
|
|
|
|
|
[global]
|
|
|
|
|
index-url = http://mirrors.tencentyun.com/pypi/simple
|
|
|
|
|
trusted-host = mirrors.tencentyun.com
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 启动
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#无后台启动
|
|
|
|
|
nohup jupyter notebook --allow-root > /data/jupyter.log 2>&1 &
|
2023-08-08 18:22:43 +08:00
|
|
|
|
|
|
|
|
%%writefile /etc/systemd/system/jupyter.service
|
2023-07-05 09:34:06 +08:00
|
|
|
[Unit]
|
|
|
|
|
Description=Jupyter Notebook
|
|
|
|
|
After=network.target
|
|
|
|
|
[Service]
|
|
|
|
|
Type=simple
|
2023-08-08 18:22:43 +08:00
|
|
|
#ExecStart 是执行文件
|
|
|
|
|
ExecStart=/root/miniconda3/bin/jupyter-notebook --config=/root/.jupyter/jupyter_notebook_config.py --allow-root
|
2023-07-05 09:34:06 +08:00
|
|
|
#文件路径名
|
|
|
|
|
Restart=always
|
|
|
|
|
RestartSec=10
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
```
|
2023-08-08 18:22:43 +08:00
|
|
|
```shell
|
|
|
|
|
ps -a 显示进程pid
|
|
|
|
|
kill -9 pid 终止进程
|
|
|
|
|
#开机自启
|
2023-07-05 09:34:06 +08:00
|
|
|
|
2023-08-08 18:22:43 +08:00
|
|
|
systemctl enable jupyter.service
|
|
|
|
|
service jupyter start
|
|
|
|
|
```
|