Exception has occurred: ModuleNotFoundErrorNo module named 'urllib3'【Solved】

Problem Description

In fact, I just want to test whether torch is installed successfully and output the corresponding version. Whoever knows is wrong.

Exception has occurred: ModuleNotFoundError

No module named 'urllib3'

 solution

(1) Use pip or conda to uninstall urllib3

pip uninstall urllib3

conda uninstall urllib3

But the above will generally report an error.

File not found.

But once you install it, it says it is satisfied, as follows:

At this time, you have to try the function of conda.

Still can't find the file: PackagesNotFoundError 

But considering that there is already in the folder just now, then go to the folder to find:

Requirement already satisfied: urllib3 in d:\program\anaconda3\envs\cat\lib\site-packages (1.26.4)

You will find that it only has urllib3-1.26.14.dist-info without urllib3. The role of the former is to display the existence of pip or conda, but because there is no latter, the module cannot be found. When installing, because it is judged that it already exists, it will not be installed, so it is Requirement already satisfied.

So the solution in this case is to delete the urllib3-1.26.14.dist-info folder in the Requirement already satisfied folder above, and then

pip install urllib3

Successful installation.

Run the program:

But the above program still has problems, as follows:

torchvision.version: <module 'torchvision.version' from 'D:\\Program\\Anaconda3\\envs\\cat\\lib\\site-packages\\torchvision\\version.py'>
torch.version <module 'torch.version' from 'D:\\Program\\Anaconda3\\envs\\cat\\lib\\site-packages\\torch\\version.py'> 

The execution result is obviously not good for the version number.

So modify it as follows:

import torch
import torchvision

print("torchvision.version:",torchvision.__version__)
print("torch.version",torch.__version__)

Because A.__version__ can get the corresponding version number, not A.version.

The result is as follows:

torchvision.version: 0.14.1+cu117
torch.version 1.13.1+cu117

 

Guess you like

Origin blog.csdn.net/a1456123a/article/details/129194096