Ubuntu20.04使用venv创建虚拟环境并安装ultralytics
vscode创建虚拟环境
在vscode中,使用ctrl + shift + p 快捷键来打开命令面板


然后选择合适的python版本即可
一般会生成如下:
安装ultralytics
先安装PyTorch,安装命令链接
1)和2)选一个
1)如果只使用CPU,如下
bash
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cpu
2)如果使用CUDA,可按需选择
bash
pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu126
再安装ultralytics

bash
pip install ultralytics
简单测试
python
from ultralytics import YOLO
# Load a model
model = YOLO("yolo11n.pt") # load an official model
# Predict with the model
results = model("bus.jpg",save=True) # predict on an image