目录

踩坑记录yolov5环境版本要求比较严苛

踩坑记录:yolov5环境版本要求比较严苛?

在安装yolov5环境时,numpy安装失败报错metadata-generation-failed

报错如下:

Collecting numpy==1.18.5 (from -r /*****/yolov5-5.0/requirements.txt (line 5))
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/01/1b/d3ddcabd5817be02df0e6ee20d64f77ff6d0d97f83b77f65e98c8a651981/numpy-1.18.5.zip (5.4 MB)
......
          replace_method(CCompiler, 'find_executables', CCompiler_find_executables)
      NameError: name 'CCompiler' is not defined
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

在python 3.7,3.8,3.9,3.10,3.12均无法正常安装numpy,或报错要求更高python版本。

遂调整requirements.txt的版本如下:

注:python要求3.8版本,否则torch可能无法安装1.7.1。

# pip install -r requirements.txt

# base ----------------------------------------
matplotlib==3.5.0
numpy==1.21.4
#numpy==1.18.5
opencv-python==4.5.4.60
Pillow==8.4.0
PyYAML==6.0
scipy==1.7.3
torch==1.7.1
#torch==1.7.0
torchvision>=0.8.1
tqdm==4.41.0

# logging -------------------------------------
tensorboard==2.8.0
# wandb

# plotting ------------------------------------
seaborn==0.11.2
pandas==1.3.4

# export --------------------------------------
# coremltools==4.1
# onnx==1.8.1
# scikit-learn==0.19.2  # for coreml quantization

# extras --------------------------------------
thop  # FLOPS computation
pycocotools==2.0  # COCO mAP

发现torch安装失败,遂使用conda进行安装:

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

此命令,conda将自动拉取所需依赖,并在虚拟环境下安装cuda,和torch相关库。

注:numpy被指定版本1.21.4, scipy被指定版本1.7.3

报错:

ModuleNotFoundError: No module named 'Cython'
No matching distribution found for pycocotools==2.0

安装对应库:

pip install Cython pycocotools==2.0