python 如何在 command 中能够找到 其他module
部分代码如下:
__author__ = 'norsd' # coding=utf8 # 上句说明使用utf8编码 try: import os import sys import time #关键语句,使得py文件能够找到其他module #关键语句,使得py文件能够双击在外部运行 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from norlib_python.Mail import HtmlMail from norlib_python.Socket import Ip except Exception,ex: print 'Load library Exception:\r\n' print ex os.system("pause") #SendComputerRebootMail if __name__ == "__main__": try: ips = Ip.GetIps() strIps = '<br/>'.join(ips)
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
这句就是关键,否则py文件可能只能跑在ide上,而不是cmd
相关链接:
http://stackoverflow.com/questions/14026996/python-cannot-find-module-from-command-line-but-works-from-eclipse