本文共 267 字,大约阅读时间需要 1 分钟。
一般我们在pycharm中run程序的时候,会将当前工程的所有文件夹路径都作为包的搜索路径;而在命令行中运行‘xxx.py’时,或者sh脚本文件运行‘xxx.py’时,只是搜索当前路径,就会找不到module
在要运行的‘xxx.py’最前面加上以下代码:
import sys,oscurPath = os.path.abspath(os.path.dirname(__file__))rootPath = os.path.split(curPath)[0]sys.path.append(rootPath)
转载地址:http://jffab.baihongyu.com/