pycharm项目可以在``运行''上运行,但是pyinstaller --onefile给出了与纸浆有关的错误

时间:2018-09-06 21:48:43

标签: python-3.x pyinstaller pulp

我一直在研究一个项目,用户可以通过纸浆上传文件进行分析。当我在pycharm中运行项目时,它可以正常工作,但是在我用pyinstaller构建--onefile之后...得到了以下回溯

Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1702, in __call__
  File "example.py", line 29, in get_file
  File "pydfs_lineup_optimizer\lineup_optimizer.py", line 351, in optimize
  File "pydfs_lineup_optimizer\solvers\pulp_solver.py", line 39, in solve
  File "site-packages\pulp\pulp.py", line 1664, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'

这是我遇到的一段代码:

import tkinter as tk
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import csv
import time
import os, sys
import PIL
from PIL import Image, ImageTk
from tkinter.font import Font




def get_file():
    global file
    file = tk.filedialog.askopenfilename()

def run_it():
    from pydfs_lineup_optimizer import Site, Sport, get_optimizer
    optimizer = get_optimizer(Site.FANDUEL, Sport.BASEBALL)
    optimizer.load_players_from_CSV(file)
    lineup_generator = optimizer.optimize(3)
    with open('Lineup.csv', "w") as csv_file:
        writer = csv.writer(csv_file, delimiter=' ')
        for lineup in lineup_generator:
            writer.writerow([lineup])

top = tk.Tk()
top.geometry("600x337")
if getattr(sys, 'frozen', False):
    baseDir = sys._MEIPASS
else:
    baseDir = os.path.abspath(os.path.dirname(__file__))

image = Image.open(os.path.join(baseDir, 'baseball.jpg'))

photo = ImageTk.PhotoImage(image)
L0 = Label(top, image=photo)

L2 = Button(top, text="UPLOAD", fg="blue", font=font2, command=get_file).grid(row=1, column=4)
L3 = Button(top, text="RUN", fg="blue", font=font2, command=run_it).grid(row=2, column=4)
top.mainloop()

1 个答案:

答案 0 :(得分:2)

Pulp需要使用cbc.exe文件才能实际解决lp问题。

不幸的是,pyinstaller默认情况下不会选中它,您需要找出一种打包cbc.ex文件的方法,然后告诉COIN_CMD()求解器在哪里找到它。

使用COIN_CMD(path=<your_path_here>)