About ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not a package

1. The package of urllib is not installed

Here I am using pycharm to do it. How to install the package will not go into details.

Solution:

    (1) pip installation

    (2) The next compiler that is so convenient to pycharm is O98K (`・ω・´)

2. The same name causes the invalidation of the urllib package

    (1) The name of the file you are importing urllib is urllib.py

    (2) There is a file called urllib.py in the folder directory of the file you are using, which causes you to import urllib to actually import the urllib.py file in the current directory, not the urllib in the library.

Solution:

    Change the name of the urllib.py file in your current directory to the same name as the imported package.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324534038&siteId=291194637