参考的博客:
Linux服务器安装Anaconda 并配置远程jupyter lab
anaconda配置远程访问jupyter,并创建虚拟环境
理解和创建:Anaconda、Jupyterlab、虚拟环境、Kernel
下边是正文了。
https://www.anaconda.com/download是官网网址,可以下载最新版本。


https://repo.anaconda.com/archive/可以下载以前的版本,注意需要选择自己需要的版本。

wget https://repo.anaconda.com/archive/Anaconda3-2023.03-1-Linux-x86_64.sh下载安装脚本。

chmod u+x Anaconda3-2023.03-1-Linux-x86_64.sh给shell脚本加上执行权限。

bash Anaconda3-2023.03-1-Linux-x86_64.sh开始安装,按一下Enter键。

然后需要一直按Enter键,直到出现"Do you accept the license terms? [yes|no]"这个提示词,然后输入yes,按下Enter键,之后输入需要安装的目录,我这里选择的是“/home/anaconda3”。

输入yes表明需要安装时进行初始化。

source ~/.bashrc激活基本环境。

重新打开远程登录,直接进入到基本环境里。

conda create -n jupyterlabuse python=3.10.9创建一个虚拟环境。

输入y。

完成之后,如下图:

conda activate jupyterlabuse激活jupyterlabuse的环境。

jupyter lab --generate-config执行之后,发现报:
-bash: jupyter: command not found

pip install jupyterlab -i https://pypi.mirrors.ustc.edu.cn/simple安装jupyterlab。

安装成功如下:

jupyter lab --generate-config生成配置文件。

使用ipython,然后输入from jupyter_server.auth import passwd;passwd(),之后输入两次一样的密码。

把单引号里边的argon2:$argon2id$v=19$m=10240,t=10,p=8$TnfU106Z+qRr7ubwSg$/Phki8t73l6+8PBfSnY4ygtbwuP8NNhUsV5MFvfxUmI保存好,因为接下来需要把它输入到/root/.jupyter/jupyter_lab_config.py里边。
然后输入exit()按下回车退出ipython。

使用sudo cat <<EOF>>/root/.jupyter/jupyter_lab_config.py把下边的内容保存到/root/.jupyter/jupyter_lab_config.py里边。
c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.open_browser = False
c.ServerApp.password = 'argon2:$argon2id$v=19$m=10240,t=10,p=8$TnfU106Z+qRr7ubwSg$/Phki8t73l6+8PBfSnY4ygtbwuP8NNhUsV5MFvfxUmI' # 上面保存的密码
c.ServerApp.port = 12345 # 服务器的端口号,下边需要使用这个端口号
每输入一行就按一下回车键。

tail -5 /root/.jupyter/jupyter_lab_config.py查看一下上边输入的内容。

nohup jupyter lab --allow-root &后台启动jupyter lab,然后按一下回车键Enter。

python -m ipykernel install --user --name jupyterlabuse --display-name "usertest"直接在环境里执行下面的代码来手动添加kernel进jupyter lab。

conda deactivate先退出虚拟环境。

ps -aux | grep "jupyter-lab"找出来对应的进程,然后使用kill -9 进程号杀死进程。

conda activate jupyterlabuse重新激活jupyterlabuse虚拟环境,nohup jupyter lab --allow-root &后台启动jupyter lab。

把ip:port/lab端口号输入到浏览器中,比如我这里在浏览器中输入192.168.53.240:12345/lab

然后按下回车,就会自动跳转到192.168.53.240:12345/login?next=%2Flab

输入密码就可以进入了,选择自己刚刚创建的名为usertest的Kernel。

点击“Select”。

右上角变成了“usertest”

此文章为9月Day 17学习笔记,内容来源于极客时间《零基础实战机器学习》。