2009-12-15 47 views

回答

0

不幸的是,py2exe已經改變了他們的作品模塊,這樣的例子提供here做不工作了。

我已經能夠通過覆蓋py2exe的一個函數來做到這一點,然後將它們插入到由py2exe創建的zip文件中。

下面是一個例子:

import py2exe 
import zipfile 

myFiles = [ 
    "C:/Users/Kade/Documents/ExampleFiles/example_1.doc", 
    "C:/Users/Kade/Documents/ExampleFiles/example_2.dll", 
    "C:/Users/Kade/Documents/ExampleFiles/example_3.obj", 
    "C:/Users/Kade/Documents/ExampleFiles/example_4.H", 
    ] 

def better_copy_files(self, destdir): 
    """Overriden so that things can be included in the library.zip.""" 

    #Run function as normal 
    original_copy_files(self, destdir) 

    #Get the zipfile's location 
    if self.options.libname is not None: 
     libpath = os.path.join(destdir, self.options.libname) 

     #Re-open the zip file 
     if self.options.compress: 
      compression = zipfile.ZIP_DEFLATED 
     else: 
      compression = zipfile.ZIP_STORED 
     arc = zipfile.ZipFile(libpath, "a", compression = compression) 

     #Add your items to the zipfile 
     for item in myFiles: 
      if self.options.verbose: 
       print("Copy File %s to %s" % (item, libpath)) 
      arc.write(item, os.path.basename(item)) 
     arc.close() 

#Connect overrides 
original_copy_files = py2exe.runtime.Runtime.copy_files 
py2exe.runtime.Runtime.copy_files = better_copy_files 
相關問題