The main share of this article is Pythonof theImporterrorErrorRelated content, come together to look at it, hope to learn Python to help you. problemError:Importerror:no module named XXXin thePythonIn a project, you occasionally encounter cases where files cannot be referenced, i.e.pycharm IDEfile jumps are supported, but the module cannot be found when the file is executed. For example, the error is as follows: Traceback (most recentPager Last): File"Utils/average_clinic.py", line 17,inch<Module> fromUtils.file_utilsImportListdir_files, show_string Importerror:NoModuleNamed File_utils SolveFirst, inPyAt the top of the file, introduce the root directory, such as Import OS Import Sys p = os.path.dirname (Os.path.dirname (Os.path.abspath (__file__)))ifP notinchSys.path: Sys.path.append (P) # Print P #Show PathSecond, check the file'sWorking directory, Location:
The first step is to import the project path, and the second step is to check the working directory of the file. First check the working directory, followed by the project path. Also, be aware thatPycharmautomatically generated file references are not necessarily correct, such as: fromFile_utilsImportListdir_files, show_string#wrong reference, file is in the same directory, no package name is used# from Utils.file_utils import listdir_files, show_stringSource:Csdn
Python Learning importerror Error