python introduced its own package python error ModelNotFoundError

python error ModelNotFoundError

Probably because the working directory is not in sys.path, the system can not locate your default script file, you can solve the problem by following command:

Import SYS >>>
>>> sys.path.append ( 'D: \ python_test') # in parenthesis working folder path
>>> referenced module import mymodel #

 

Check the configuration of the path: the command line or in python .py file

import sys
sys.path

 

 

 

 

 

 Add the path by the command:

sys.path.append("C:\Users\DELL\Desktop\test")

In this way the path was added.

 

In python project, py file, we can use the following method

My file directory like this

pythonproject\main\data\test.py
pythonproject\main\common\mysqlutil.py

 

# test.py
import
os import sys ProjectName = ' pythonproject ' # Get the current file curPath = os.path.abspath with (os.path.dirname ( __FILE__ )) # Print (curPath) # match project from the back # path curPath = [0: curPath.rfind (ProjectName)] rootPath curPath = [0: curPath.rindex (ProjectName)] + ProjectName Print (rootPath) # in parenthesis working folder path # modules referenced # sys.path.append (R & lt '\ path \ to \ file \ pythonproject \ main \ the Common ') # Import mysqlutil # sys.path.append(r'\path\to\file\pythonproject') # import main.common.mysqlutil # from main.common import mysqlutil # Sys.path.append (rootPath) sys.path.append (rootPath) # I own modules in the project are from main.common Import mysqlutil def test1(): print() def main(): test1() # Determine whether it is the program's main entrance, if it is the program's main entrance, the code block is executed, otherwise it does not execute code block # is mainly used when people call this code, do not enter the code entry IF __name__ == " __main__ " : main()

 

Guess you like

Origin www.cnblogs.com/zhangchao0515/p/12549646.html