Bootstrap

解决方案:Error loading nvfuser_codegen.dll、cannot import name ‘packaging‘、ImportError: libGL.so.1、字体问题

一、PyTorch安装中出现OSError: [WinError 126] 找不到指定的模块

1.1、问题描述

安装PyTorch后,import torch出现:

OSError: [WinError 126] 找不到指定的模块。 Error loading “D:\Anaconda\envs\torch2\lib\site-packages\torch\lib\nvfuser_codegen.dll” or one of its dependencies.

1.2、解决方案

这个还是安装的时候出的问题,建议重新安装PyTorch,这里给出CUDA 11.8、PyTorch2.1.2的安装指令:

conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=11.8 -c pytorch -c nvidia

二、torchvision安装中出现 cannot import name ‘packaging’ from ‘pkg_resources’

2.1、问题描述

安装PyTorch后,import torchvision出现:

ImportError: cannot import name ‘packaging’ from ‘pkg_resources’ (D:\Anaconda\envs\torch2\lib\site-packages\pkg_resources_init_.py)

2.2、解决方案

先检查setuptools是否为70.0.0及以上的版本,比如使用conda list检查:
在这里插入图片描述
如果是70.0.0及以上的版本,需要降低版本

python -m pip install setuptools==69.5.1

三、 matplotlib安装中出现Could not fetch URL https://pypi.python.org/simple/matplotlib/

3.1、问题描述

Collecting matplotlib>=3.3 (from -r requirements.txt (line 5))
Could not fetch URL https://pypi.python.org/simple/matplotlib/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748) - skipping
Could not find a version that satisfies the requirement matplotlib>=3.3 (from -r requirements.txt (line 5)) (from versions: )
No matching distribution found for matplotlib>=3.3 (from -r requirements.txt (line 5))

3.2、解决方案

这是pip源的问题,选择国内源即可解决:

pip install matplotlib -i http://pypi.douban.com/simple/

四、ImportError: libGL.so.1: cannot open shared object file: No such file or directory

4.1、问题描述

File “/opt/conda/lib/python3.10/site-packages/cv2/init.py”, line 181, in
bootstrap()
File “/opt/conda/lib/python3.10/site-packages/cv2/init.py”, line 153, in bootstrap
native_module = importlib.import_module(“cv2”)
File “/opt/conda/lib/python3.10/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

这个错误表明Python程序试图导入一个模块或库,而这个库依赖于名为libGL.so.1的共享对象文件,但是系统无法找到这个文件。libGL.so.1是OpenGL的GPU渲染库,通常由图形驱动程序提供。

4.2、解决方案

安装依赖项 libgl1 就可以了,指令如下:

apt-get update && apt-get install libgl1

五、找不到Arial.ttf或者Arial.Unicode.ttf导致的报错

5.1、问题描述

File “/root/workspace/YOLO/utils/general.py”, line 581, in check_dataset
check_font(“Arial.ttf” if is_ascii(data[“names”]) else “Arial.Unicode.ttf”, progress=True) # download fonts
File “/root/workspace/YOLO/utils/general.py”, line 516, in check_font
torch.hub.download_url_to_file(url, str(file), progress=progress)
File “/opt/conda/lib/python3.10/site-packages/torch/hub.py”, line 597, in download_url_to_file
u = urlopen(req)

5.2、解决方案

可以在github上找到Arial.Unicode.ttf 字体,进行下载:https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf
下载好后,使用mv指令存到linux系统的字体位置中,如:

mv Arial.Unicode.ttf  /root/.config/Ultralytics/
;