如何使用py2app修复“找不到模块”?

时间:2019-06-06 16:35:12

标签: python macos py2app

我正在尝试将python代码转换为Mac的独立应用程序。我能够成功运行python setup.py py2app,但收到警告:

Modules not found (conditional imports): * StringIO (docx.compat) * _frozen_importlib_external (importlib._bootstrap) * java (platform) * java.lang (platform)

当我尝试使用它时,我的应用程序崩溃了。

这是我的python代码:

# importing tkinter and tkinter.ttk 
# and all their functions and classes 
from tkinter import * 
from tkinter.ttk import *

# importing askopenfile function 
# from class filedialog 
from tkinter.filedialog import askopenfile 

csv_file_name = ""

root = Tk()
root.withdraw() # Hides the tkinter window
filename = askopenfile(parent=root,mode='r',filetypes=[('CSV file','*.csv')],title='Choose a CSV file')
if filename != None:
    # print(filename.name) 
    csv_file_name = filename.name

if csv_file_name != "":
    import csv
    data = []
    with open(csv_file_name, newline='') as csvfile:
        reader = csv.reader(csvfile, delimiter=',', quotechar='|')
        for row in reader:
            data.append(row)
    # print(data)

    from docx import *

    document = Document()

    table = document.add_table(rows=0, cols=3)
    table.style = 'Table Grid' 
    for person in data:
        time = person[0]
        actor = person[1] + " " + person[2]
        role = person[3]
        agent = person[4]
        row_cells = table.add_row().cells
        row_cells[0].text = time + "\n" + actor + "\n" + role + "\n" + agent + "\n" + "# ________"

    document.add_page_break()

    desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')

    document.save(desktop + '/demo.docx')

我已经尝试修复了几个小时,但是没有运气。我只是不明白如何解决缺少的模块问题。

编辑:

这是我的setup.py文件:

"""
This is a setup.py script generated by py2applet

Usage:
    python setup.py py2app
"""

from setuptools import setup

APP = ['csv2word.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

0 个答案:

没有答案