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

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

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐