使用poetry配置深度学习环境
什么是poetry??
可以查看poetry的官方文档:放在这里,感兴趣可阅读:poetry 官网文档
配置过程
是我自己学习后的精简版本,如果想知其然知其所以然的,参考上面的官网文档。
- 背景:已经安装好了annaconda,有当前的配置文件pyproject.toml
- 使用conda创建一个虚拟环境:
conda create -n dl python==3.10
- 安装好之后激活该环境:
conda activate dl
- 安装pipx(为安装poetry做准备):
pip install pipx
- 安装poetry:
pipx install poetry
- 将poetry的安装地址加入系统变量
- 进入配置文件pyproject.toml所在的根目录进行配置:
poetry install
注意事项
- step1中,创建虚拟环境的时候,安装python的版本要符合配置文件pyproject.toml中的依赖要求:
- step3-4,最好先安装pipx再安装poetry,不要直接使用pip或者conda安装【避免不必要的error】
- step6中安装前先将自己的梯子关了
粉丝福利
深度学习的配置环境文件pyproject.toml:里面涵盖了很多深度学习需要的package
[tool.poetry]
name = "algorithm"
version = "0.2.0"
description = ""
authors = ""
license = "MIT"
readme = "README.md"
# 清华
[[tool.poetry.source]]
name = "tsinghua"
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
priority = "default"
[[tool.poetry.source]]
name = "PyPI"
priority = "primary"
[[tool.poetry.source]]
name = "aliyun-source"
url = "https://mirrors.aliyun.com/pypi/simple/"
priority = "supplemental"
[[tool.poetry.source]]
name = "pytorch-cu117"
url = "https://download.pytorch.org/whl/cu117"
priority = "explicit"
[[tool.poetry.source]]
name = "pytorch-cu118"
url = "https://download.pytorch.org/whl/cu118"
priority = "explicit"
[tool.poetry.dependencies]
python = ">=3.10,<3.11"
# tools
python-dotenv = "^1.0.0"
click = "^8.1.3"
tqdm = "^4.64.0"
typer = { extras = ["all"], version = "^0.7.0" }
joblib = "^1.2.0"
munch = "^2.5.0"
# poetry plugin
poethepoet = "^0.16.2"
# network
requests = "^2.28.1"
# table
pandas = "^1.5.3"
openpyxl = "^3.0.10"
xlsxwriter = "^3.0.3"
prettytable = "^3.4.1"
# jupyter
jupyterlab = "^3.4.5"
jupyter = "^1.0.0"
notebook = "^6.4.12"
# fig
matplotlib = "^3.5.3"
seaborn = "^0.11.2"
visdom = "^0.1.8.9"
pydotplus = "^2.0.2"
graphviz = "^0.20.1"
# html
dominate = "^2.7.0"
varname = "^0.11.0"
# doc
python-docx = "^0.8.11"
# pdf
PyPDF2 = "^2.10.4"
# image
opencv-python = "4.5.5.64"
Pillow = "^9.5.0"
imutils = "^0.5.4"
# nlp
transformers = "^4.20.1"
jieba = "^0.42.1"
# ml
scikit-learn = "^1.3.0"
scikit-image = "^0.19.3"
keras = "^2.9.0"
scipy = "^1.8.1"
sympy = "^1.10.1"
fastai = "^2.7.11"
mlxtend = "^0.21.0"
scanpy = "^1.9.3"
# dl
einops = "^0.4.1"
wandb = "^0.13.3"
tensorboard = "^2.10.0"
tensorboardX = "^2.5.1"
tensorlayer = "^2.2.5"
# torch
albumentations = "^1.3.0"
accelerate = "^0.16.0"
timm = "^0.9.2"
torchgeometry = "^0.1.2"
torchsummary = "^1.5.1"
torchkeras = "^3.2.3"
torchsampler = "^0.1.2"
pytorch-lightning = "^1.9.4"
segmentation-models-pytorch = "^0.3.3"
# Interpretability
grad-cam = "^1.4.6"
torchcam = "^0.3.2"
captum = "^0.6.0"
shap = "^0.42.1"
lime = "^0.2.0.1"
# openmmlab
openmim = "^0.3.1"
# tensorflow
tensorflow = "^2.9.1"
# gpu
gpustat = "^1.0.0"
[tool.poe.tasks.torch-cpu]
cmd = "pip3 install torch torchvision torchaudio"
[tool.poe.tasks.torch-cpu-conda]
cmd = "conda install pytorch torchvision torchaudio cpuonly -c pytorch"
[tool.poe.tasks.torch-gpu]
cmd = "pip install torch torchvision torchaudio --upgrade --extra-index-url https://download.pytorch.org/whl/${CUDA}"
args = [
{ name = "CUDA", default = "cu116", positional = true, help = "CUDA version" }
]
[tool.poe.tasks.torch-gpu-conda]
cmd = "conda install pytorch torchvision torchaudio cudatoolkit=${CUDA} -c pytorch -c conda-forge"
args = [
{ name = "CUDA", default = "11.6", positional = true, help = "CUDA version" }
]
[tool.poe.tasks.mmcv]
cmd = "mim install mmcv-full"
[tool.poe.tasks.R]
cmd = "conda install r-irkernel -c r -y"
[tool.poe.tasks.cplusplus]
cmd = "conda install xeus-cling -c conda-forge -y"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"