note/note/learn/lib/环境搭建/环境搭建.md
2023-08-25 22:34:04 +08:00

2.4 KiB
Raw Blame History

1. 修改主机名

创建工作空间

  • mkdir /data && mkdir /data/jupyter && cd /data/jupyter

conda 环境配置

  • 下载
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

  • 更换清华镜像源

    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

    conda config --set show_channel_urls yes

  • 安装 jupyter 在 base 环境

    
    
  • conda默认会有个base环境在base环境下安装东西容易破坏掉conda

    • 创建环境

      • conda create -n py27 python=2.7
        

支持 python2 和 python3

  • py2

    • conda create -n py27 python=2.7
      conda activate py27
      conda install notebook ipykernel
      python -m ipykernel install --user --name py27 --display-name "python2.7"
      conda deactivate #退出py27环境
      
  • py3 默认已支持不需要

    • 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
  • 配置 jupyter notebook

    • jupyter kernelspec list
      jupyter kernelspec remove
      

      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' #输入上面加密后得到的密文
      
  • start.sh

#!/bin/sh
result=`ps -ef | grep -o jupyter-notebook`
array=(`echo $result | tr ' ' ' '` )  
length=${#array[@]}
#kill -9 $(ps -ef | grep jupyter-notebook | grep -v grep | awk '{print $2}')
if [ $length -gt 2 ] 
then 
	echo "jupyter-notebook is running"
else 
	`nohup jupyter notebook --allow-root > /data/jupyter.log 2>&1 &`
	echo "start success jupyter-notebook"
fi

更新 pip 源

安装 zcmd 库

nohup jupyter notebook --allow-root > /data/jupyter.log 2>&1 & 。。。