✅ 远程深度学习新环境配置流程

1. 安装 Miniconda

前往 Miniconda官网 下载并安装适合你系统的 Miniconda 版本。

2. 配置国内源

pip 换源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

conda 换源

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

3. 创建 Conda 环境

conda create -n jupyterlab python=3.13 -y
conda activate jupyterlab

4. 安装 Jupyter Lab

pip install jupyterlab
jupyter-lab --generate-config

5. 配置远程访问

修改 ~/.jupyter/jupyter_lab_config.py 文件,加入:

c.ServerApp.ip = '0.0.0.0'
c.ServerApp.open_browser = False
c.ServerApp.port = 8899
c.ServerApp.allow_remote_access = True

6. 设置密码(推荐)

from jupyter_server.auth import passwd; print(passwd())

将生成的 hash 写入配置文件:

c.ServerApp.password = 'argon2:...'

7. pip 包定制安装路径

#!/bin/bash

PYTHON_VERSION=3.13
ENV_NAME=jupyterlab
CUSTOM_PATH="$HOME/miniconda3/python_packages/python${PYTHON_VERSION}"
SITE_PACKAGES_PATH="$HOME/miniconda3/envs/${ENV_NAME}/lib/python${PYTHON_VERSION}/site-packages"
PIP_CONF_PATH="$HOME/miniconda3/envs/${ENV_NAME}/.pip/pip.conf"
PTH_FILE="${SITE_PACKAGES_PATH}/custom_path.pth"

mkdir -p "$(dirname "$PIP_CONF_PATH")"
echo "[global]" > "$PIP_CONF_PATH"
echo "target = ${CUSTOM_PATH}" >> "$PIP_CONF_PATH"

mkdir -p "$CUSTOM_PATH"
mkdir -p "$SITE_PACKAGES_PATH"
echo "$CUSTOM_PATH" > "$PTH_FILE"

python${PYTHON_VERSION} -m pip install requests
python${PYTHON_VERSION} -c "import requests; print('✅ 成功导入 requests:', requests.__version__)"

8. 启动 Jupyter Lab

jupyter lab

然后访问 http://<服务器IP>:8899。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐