使用py2exe时,获取'tuple'对象没有属性'split'

时间:2015-07-17 11:15:48

标签: python python-2.7 py2exe

我正在使用Py2exe为我的GUI创建一个可执行应用程序,这是我的设置代码:

import matplotlib
from distutils.core import setup
import FileDialog
import zmq.libzmq

import py2exe
setup(
 data_files=[matplotlib.get_py2exe_datafiles(),(zmq.libzmq.__file__,)],
 console = [{'script': 'SVS-virtual-lib2.py'}],
 options={
         'py2exe': {
                 'packages': ['FileDialog'],
                 'includes': ['zmq.backend.cython'],
                 'excludes': ['zmq.libzmq'],
                 'dll_excludes': ['libzmq.pyd']
                 }
        }
)

但我收到以下错误:

  File "C:\Users\nzarinabad\AppData\Local\Continuum\Anaconda\lib\distutils\util.py", line 128, in convert_path
    paths = string.split(pathname, '/')
  File "C:\Users\nzarinabad\AppData\Local\Continuum\Anaconda\lib\string.py", line 294, in split
    return s.split(sep, maxsplit)
AttributeError: 'tuple' object has no attribute 'split

为什么我得到错误以及如何修复它? 谢谢

1 个答案:

答案 0 :(得分:1)

请参阅the documentation,如果您想将matplotlib.get_py2exe_datafiles()与其他文件合并,则必须进行一些手动操作:

from distutils.core import setup
import py2exe

from distutils.filelist import findall
import os
import matplotlib
matplotlibdatadir = matplotlib.get_data_path()
matplotlibdata = findall(matplotlibdatadir)
matplotlibdata_files = []
for f in matplotlibdata:
    dirname = os.path.join('matplotlibdata', f[len(matplotlibdatadir)+1:])
    matplotlibdata_files.append((os.path.split(dirname)[0], [f]))

matplotlibdata_files.append(zmq.libzmq.__file__)

# ...

setup(
 data_files=matplotlibdata_files,
# rest of your code