要在 CentOS 上安装 JupyterLab,可以按照以下步骤操作:
-
确保已经安装 Python 3.9。你可以在终端上运行以下命令来检查 Python 的版本:
python3.9 --version
-
安装 JupyterLab 和所需的依赖项。在终端上运行以下命令:
pip3 install jupyterlab
此命令将使用 pip3.9 来安装 JupyterLab。
-
生成配置文件: 如果还没有生成 JupyterLab 的配置文件,可以在终端运行以下命令生成:
jupyter lab --generate-config
-
生成密码哈希值:在终端上运行以下命令生成密码哈希值:
python3.9 -c "from notebook.auth import passwd; print(passwd())"
这将生成一个密码哈希值。如果出现 not found notebook module,可以通过pip3 install notebook 解决
-
编辑配置文件: 打开 JupyterLab 的配置文件,可以使用任何文本编辑器打开生成的配置文件(一般位于
~/.jupyter/jupyter_lab_config.py
)。将以下内容添加到配置文件末尾:c.ServerApp.password = '<生成的密码哈希值>' c.ServerApp.ip = '0.0.0.0' c.ServerApp.open_browser = False c.ServerApp.allow_remote_access = True
将
<生成的密码哈希值>
替换为第二步生成的密码哈希值。这将允许远程访问 JupyterLab。 -
启动 JupyterLab:在终端上运行以下命令:
nohup jupyter lab --allow-root &
如果出现以下报错,可以将通过 pip3 install requests==2.29.0 解决
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168
7. 浏览器访问: 在本地浏览器上访问jupyterlab
http://ip:8888/lab, 其中ip为你centos服务器的公网地址,且需要再安全组中打开8888端口。
现在,你已经成功在 CentOS 上安装并启动了 JupyterLab。你可以使用 JupyterLab 来创建和运行 Jupyter Notebook,进行交互式的 Python 编程和数据分析任务。