在python代码中执行这条命令行语句,
os.system('python2 online/end_to_end.py --in_files=../data/gd_20171218.test.xls --to_dir=../out --threshold=0.9')
爆出如下错误:
No module named "xxx"
发现在JetBrains运行时,会将当前工程的所有文件夹路径都作为包的搜索路径;
而在命令行中运行时,只是搜索当前路径,当然找不到module咯。
解决方案:
最上面引入:
import sys
import os
curPath = os.path.abspath(os.path.dirname(__file__))
rootPath = os.path.split(curPath)[0]
sys.path.append(rootPath)
读者可以执行如下语句查看输出,进行调试:
print curPath
print rootPath