我有個很不好的習慣,就是喜歡直接在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)