Python .py file command line prompt ModuleNotFoundError: No module named 'XXX' solution

The reason: In the command line package .py file can not be found because we do not have to save the project path, you can save the project path through sys.path.append (), after the execution can be successful.

# ######################################## save the project path ###### ################################### 
Import SYS
 Print (sys.path)
 # get the project directory path 
# project path 
project_path = ' E: / COVID-19CTimageAnal / source / 3DUnetCNN ' 
os.chdir (project_path) 
for File in os.listdir (os.getcwd ()):
     Print (File)
 # save the project path 
sys.path. the append (project_path)
 # ######################################## save the project path ## ####################################### 

# If you want to import another module name of the project, the method should be written after the introduction of the method described above:
from brats.train import config
 

Project directory as shown:

 

Guess you like

Origin www.cnblogs.com/dyc99/p/12535941.html