Cloud Studio 搭建 anaconda 环境 安装 jupyter notebook

以下使用腾讯云的 Llama3.2 - RAG SFT练习 空间模板

Conda 环境

该空间模板已安装好 Conda 环境

conda_02

更换国内源

使用清华的国内源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes

创建虚拟环境

使用 Conda 创建独立的 Python 环境,可以避免不同项目间的依赖冲突。

# 创建一个 3.10 版本的环境 jupyter_env
conda create -n jupyter_env python=3.10 -y

然后就开始安装环境的依赖,可以看到这里使用的 python-3.10.16

conda_03

激活环境

安装完成后,就可以激活 jupyter_env 环境

conda activate jupyter_env

切换清华源

由于更新过快难以同步,我们不同步pytorch-nightly,pytorch-nightly-cpu,ignite-nightly这三个包。

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/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/
conda config --set show_channel_urls yes

安装 Jupyter Notebook

在激活的虚拟环境中,运行以下命令安装 Jupyter Notebook

conda install jupyter notebook

安装完成后,验证安装

jupyter notebook --version

conda_04

启动 Jupyter Notebook

允许 root 方式启动,并允许远程访问

jupyter notebook --allow-root --ip=0.0.0.0 --port=8888

使用

ngrok 安装

使用内网渗透工具,就可在外网访问,具体查看 Cloud Studio 软件环境安装 的相关介绍

绑定端口

绑定 8888 端口

ngrok http 8888

打开 jupyter 面板

点击 ngrok 的公网地址,就看到以下页面

jupyter_01

这里会提示输入 token,我们可以通过命令行查找

# 必须要在虚拟环境 jupyter_env 内执行
jupyter server list

jupyter_02

输入 token 后就可以看到面板

jupyter_03

新建文件

我们右键新建一个 notebook 目录,然后新建我们的测试文件 demo1.ipynb,这里要注意使用 Python 3(ipykernel),这个才是上面在虚拟环境创建的 python3.10.16 环境

jupyter_04

我们可以验证一下

jupyter_05

而腾讯云使用的 python3.10.11
jupyter_06

测试

最后我们就可以这个环境下做测试,例如我这边是调用 openai 的接口,使用的 腾讯云 提供的免费接口,它与 openai 兼容

jupyter_07

其他事项

安装 conda

如果容器中没有 conda,需要自行安装

https://repo.anaconda.com/archive/

下载安装脚本

# 大概有1G
wget https://repo.anaconda.com/archive/Anaconda3-2024.10-1-Linux-x86_64.sh

安装

按照提示安装即可

bash Anaconda3-2024.10-1-Linux-x86_64.sh

版权声明:
作者:lrbmike
链接:https://blog.liurb.org/2025/02/15/cloud-studio-anaconda-jupyter-notebook/
来源:大卷学长
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>