Solve the problem: ImportError: cannot import name ‘_update_worker_pids‘

When reproducing some earlier documents, the network architecture was an earlier Pytorch model. The current higher version is not compatible, so you have to install a lower version of torch==0.4.0 to solve the problem.

1. Problem

问题:ImportError: cannot import name ‘_update_worker_pids’

Insert image description here

A lower version of Pytorch is required when the following situations occur:

Insert image description here

1.1 Problem analysis

This error may be due to a problem with the PyTorch version. _update_worker_pids etc. are internal functions of PyTorch and may not exist in some versions.

2. Solution

Note: Python version must be less than or equal to 3.6

2.1 Pytorch installation

Use the following command to install version 0.4.0 of Pytorch.

pip install torch==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

The installation in the corresponding virtual environment of the terminal is as follows:

Insert image description here

2.2 torchvision installation

Corresponding to version 0.4.0 in the previous step, torchvision must be 0.2.0. If you don’t believe it, you can try other versions.

The command to install torchvision is as follows:

pip install torchvision==0.2.0 -i https://pypi.mirrors.ustc.edu.cn/simple/

The installation in the corresponding virtual environment of the terminal is as follows:

Insert image description here

2.3 Test whether the installation is successful

The above installed look is as follows:

Insert image description here

Test in the code. If there is no red line underlined or an error reported, it means the installation has been successful, as follows:

Insert image description here

3. Summary

The above is the process of solving the problem: ImportError: cannot import name '_update_worker_pids’. I hope it can help you.

It’s not easy to summarize, thank you for your support, Sherer!

Guess you like

Origin blog.csdn.net/qq_40280673/article/details/135012798