Skip to content

conda、uv 和 jupyter

conda

创建环境

bash
conda create -n dl-jupyter python=3.11

列出环境

bash
conda env list

激活环境

bash
conda activate dl-jupyter

退出环境

bash
conda deactivate

删除环境

bash
conda remove -n dl-jupyter --all

uv

运行程序

bash
uv run app.py

安装包

bash
uv pip install fastapi uvicorn dotenv socksio

卸载包

bash
uv pip uninstall requests

列出包

bash
uv pip list

# 仅列出非依赖包
uv run python -m pip list --not-required

导出包

bash
uv pip freeze > requirements.txt

# 仅导出非依赖包
uv run python -m pip list \
    --not-required \
    --format=freeze > requirements-manual.txt

jupyter

本地启动

bash
jupyter lab
#jupyter notebook

配置 conda 虚拟环境到 jupyter

bash
uv pip install ipykernel

python3 -m ipykernel install --user --name english-asr --display-name "conda (english-asr)"

删除 jupyter 的 conda 虚拟环境

bash
jupyter kernelspec remove english-asr

配置自动补全:

  1. 开启代码自动补全 Settings -> Code Completion -> Enable autocompletion
  2. 开启括号自动补全 Settings -> Auto Close Brackets

实战:准备一个 jupyter 深度学习环境

bash
# 准备 conda 虚拟环境
conda create -n dl-jupyter python=3.10
conda activate dl-jupyter

# 安装包
uv pip install numpy pandas matplotlib
# uv pip install seaborn tqdm
uv pip install torch torchvision torchaudio \
    --index-url https://download.pytorch.org/whl/cpu

# 将虚拟环境添加到 jupyter
uv pip install ipykernel
python -m ipykernel install --user \
    --name dl-jupyter \
    --display-name "Conda (dl-jupyter)"