Reference: [Python] [Study] Introduction to Python (35) --Import processing
tqdm.py
from tqdm import tqdm
from time import sleep
for i in tqdm(range(10)):
sleep(1)
Output
Traceback (most recent call last):
File "./tqdm.py", line 1, in <module>
from tqdm import tqdm
File "~/tqdm.py", line 1, in <module>
from tqdm import tqdm
ImportError: cannot import name tqdm
This is an error that occurred when I casually made the file name the same as a new module test.
This can be avoided by simply renaming the file.
Quoted from reference
__1. Find the module file to import __ A module search path is used to search for module files. Basically, the module search path is set automatically. The module search path has four elements. The elements are described below.
- Home directory of top-level files
- The directory specified by the environment variable PYTHONPATH
- Standard library module directory
- Contents of .pth file
When changing the module search path, usually change the environment variable PYTHONPATH or .pth. 1 is searched first, otherwise 2. Finally 4 is searched.
__ Home directory of top level files __ The home directory is usually the directory where top-level files are located. The first location to be searched when importing a module.
__ Environment variable PYTHONPATH__ An environment variable that describes the directory path that depends on the environment. Multiple values can be set, and if multiple values are specified, the search will be performed in order from the left end. The set value will be the location next to the home directory of the top-level file.
__Standard Library Module Directory __ The directory where the standard library is installed. Where to look next to the value of the environment variable PYTHONPATH.
__.pth file contents __ You can specify multiple lines, one pass per line. If you put this file in the "appropriate place" Searches for the location of the value in each line, starting from the first line in the contents of the .pth file. It is currently unknown where the "appropriate place" is.
__ "Oss! Oh, tqdm.py is a file! I call tqdm with import, but I don't know such a module. But I wonder what to do because I'm called ... I'll just throw an error! !! "__
It's almost right.
Recommended Posts