Operation and maintenance series (11)--Execute python on the command line, prompting No module named "xxx"

Execute this command line statement in python code,

os.system('python2 online/end_to_end.py --in_files=../data/gd_20171218.test.xls --to_dir=../out --threshold=0.9')   

The following error pops up:

No module named "xxx"

It is found that when JetBrains is running, all folder paths of the current project are used as the search path of the package;

When running on the command line, it just searches the current path, of course, the module cannot be found.
Solution:
Introduce at the top:

import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)

Readers can execute the following statement to view the output and debug:

print curPath 
print rootPath 

Guess you like

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