【发布时间】:2020-07-10 14:32:12
【问题描述】:
我正在开展一个使用纸浆进行线性优化的项目。当我通常“运行”该文件时,它运行良好,但是当我尝试使用 pyinstaller 将其转换为 .exe 文件时遇到了一些问题。 如果我从命令提示符运行 .exe 文件,则会报告错误:
Traceback (most recent call last):
File "price.py", line 116, in <module>
File "site-packages\pulp\pulp.py", line 1713, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'
[9468] Failed to execute script price
我遇到问题的代码部分:
#type of problem
group_division = pulp.LpProblem("Group_division", pulp.LpMinimize)
#objective function to minimize
group_division += objectiveFunction(external_groups, internal_groups)
#specify the maximum number of groups
group_division += sum([x[group] for group in external_groups]) <= max_groups,
"Maximum_number_of_groups"
#every thickness must appear once
for cutType in cutTypes:
group_division += oneCutConstraint(x, y, external_groups, internal_groups, cutType) ==
1,"Must_appear_%s"%cutType
#solve the problem
group_division.solve()
【问题讨论】:
-
您能否分享最少的代码来重现问题?看起来你最终得到了一个 NoneType 对象,你应该有一个求解器对象。我猜是因为当你从可执行的纸浆中运行时看不到求解器。作为 python 代码运行时,您使用什么求解器?
-
@kabdulla 我用 spyder 和 JupyterLab 运行代码,我没有错误。我认为 pyinstaller 和纸浆有一些“沟通”问题。你怎么看?
-
据我所见,pyinstaller 运行环境中找到了纸浆库,但似乎找不到求解器(与纸浆分开)。
-
检查 id 建议运行(本地然后通过 pyinstaller-gnerated exe)以下
pulp.pulpTestAll()。然后,您将知道从哪里可以使用哪些求解器。 -
嗯...过去你可以按照此处的说明执行
import pulp,然后是pulp.pulpTestAll():coin-or.org/PuLP/main/…
标签: python python-3.x optimization pyinstaller pulp