py2exe打包数据文件

时间:2013-01-14 12:03:24

标签: python file installation py2exe

我有一个应用程序打包,其中包含一个图像作为数据文件,我尝试运行此setup.py脚本:

from distutils.core import setup
import py2exe
import matplotlib

file_dati=[]
file_dati.append(matplotlib.get_py2exe_datafiles())
file_dati.append(('img1','C:\Users\MZompetta.000\Desktop\20130114_assortimenti\img1.gif'))

setup(console=[{"script": "Int_assortimenti.py"}],
       options = {
        "py2exe": {
            "dll_excludes": ["libzmq.dll", "MSVCP90.dll"]
        }
    }, data_files=file_dati
)

但我得到了这个错误:

  

AttributeError:'tuple'对象没有属性'split'

该错误被引用到该行:data_files=file_dati

我尝试了其他方法来编写data_files,但没办法。

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:1)

import os
import logging
from distutils.core import setup
import py2exe
import matplotlib
import shutil

distDir = "dist"

# Remove the build and dist folders
shutil.rmtree("build", ignore_errors=True)
shutil.rmtree("dist", ignore_errors=True)

try:
    os.mkdir(os.path.abspath(distDir))
except:
    logging.exception('')

data_files = matplotlib.get_py2exe_datafiles()
shutil.copyfile('C:\Users\MZompetta.000\Desktop\20130114_assortimenti\img1.gif', os.path.join(distDir, "img1.gif"))

setup(
    options = {"py2exe": {
            "dll_excludes": ["libzmq.dll", "MSVCP90.dll"],
            "dist_dir": distDir,
        }
    }
    data_files = data_files,
    console=[{"script": "Int_assortimenti.py"}],
)