python 打包好后出现 failed to execute script问题
我有个很不好的习惯,就是喜欢直接在class下面直接写class的测试用的代码, 比如这种:
class SVN(): def __init__(self): self.setting = { 'svn':'C:/Program Files/TortoiseSVN/bin/', # svn的程序所在路径 'url':'', # svn地址 'user':'', 'pwd':'', 'dist':'D:/SVN_Block/Version1/SampleProject/', # 目标地址 'interval': 15, # 更新时间 'num':5 } self.project_url = { 'pre7_419':'', 'pre7_424':'', 'post7_424':'' } def set_user(self, string): self.setting['user']=string def exec_cmd(self, username=''): # pprint.pprint(time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime())) # cmd='svn update %(url)s %(dist)s --username %(user)s'%setting #export, dont use it # cmd = 'svn update %(dist)s --username %(user)s' % setting #update svn line = 3 if(username ==''): cmd = 'svn log %(url)s -l %(num)s' % self.setting else: cmd ='svn log %(url)s --search %(user)s -l %(num)s' % self.setting result = "execute %s" % cmd # print (result) return cmd def get_cmd_result(self, cmd): r = os.popen(cmd) text = r.read() r.close() return text client = util.get_client(r'D:\SVN_Block\Version1\SampleProject') info = client.info() remote_client = remote.RemoteClient(r'file:///H:/SVNHook/branches/Version1/SampleProject') r_info = remote_client.info() r_log = remote_client.log_default() for i in r_log: print (i)
然后到最后打包的时候虽然class外的代码没有使用到,但是编译器会不管三七二十一编译一遍,程序在我电脑上运行是不会出错的,但在同事电脑上就不行了, 原因是因为, 注意这里有个remoteClient和get_client用的路径是绝对路径。虽然没有在UI里执行但是会编译,所以会直接报错.
如果程序里真的有绝对路径但是又不知道在哪的话可以在打包的时候用--debug=all来看运行过程(打包我用的是PyInstaller)