在文件头部加入
base_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.dirname(base_dir))
设置sys.path 变量 既可以在pycharm运行 也可以在命令行运行
实际应用
import time, requests, os, re, xlrd, win32com.client, pythoncom, sys
base_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.dirname(base_dir))
参考
https://blog.csdn.net/xdreamman/article/details/106880873