PyInstaller and PuLP

2,382 views
Skip to first unread message

Lucas Guido

unread,
Nov 17, 2016, 10:39:37 PM11/17/16
to pulp-or-discuss
Dear gentlemen,

I modeled and programmed a LP with PuLP 1.6 over Python 3.5.2, working perfectly when I run the script. Nice!

Now my challenge is putting it in a EXE file, and for this I'm using PyInstaller. Here I have some trouble.
I receive the following error message when trying to run my EXE:

[...]
   File "site-packages\pulp\pulp.py", line 1643, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'
Failed to execute script myLP


My best guess is that compiled code don't have success on finding standard solver, so I need to manually point it in my code.
Am I right? How would I do it?

For me would be very interesting, if possible, not to install a solver or deal with environment variables. Best case would be download the solver and point the file inside the code (for example C:/folder1/folder2/solver.xyz).

Note 1: Code works perfecty when runed as script, including the solver. The problem happens only when I run it as EXE.
Note 2: The problem isn't numpy or related libraries, I already checked it out.

Please, light my path.

Tks in advance!
Lucas Guido

Stuart Mitchell

unread,
Dec 5, 2016, 3:21:04 PM12/5/16
to pulp-or...@googlegroups.com
you can point to a particular version of the standard solver (cbc) when you use the COIN_CMD solver

prob.solve(COIN_CMD(path = "C:/folder1/folder2/solver.xyz"))

hope this helps

Stu

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/pulp-or-discuss.
For more options, visit https://groups.google.com/d/optout.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Lucas Guido

unread,
Dec 21, 2016, 9:03:32 PM12/21/16
to pulp-or-discuss
Hi Stu,

Here is what I did:

1. I downloaded CBC binary from http://www.coin-or.org/download/binary/Cbc/ and, in my case, I selected Cbc-2.7.5-win64-intel11.1.zip
2. I coded as follows:

import os
cwd
= os.getcwd()
solverdir
= 'cbc-2.7.5-win64\\bin\\cbc.exe'  # extracted and renamed CBC solver binary
solverdir
= os.path.join(cwd, solverdir)
solver
= pulp.COIN_CMD(path=solverdir)
model
.solve(solver)

3. I then ran pyinstaller and dropped the unzipped binary folder (Cbc-2.7.5-win64-intel11.1 that I renamed to cbc-2.7.5-win64) into the same folder of my executable (inside the dist folder).

Works like a charm.

Basically I followed the steps of shudohmaster.

Thanks!



Em segunda-feira, 5 de dezembro de 2016 18:21:04 UTC-2, Stuart Mitchell escreveu:
you can point to a particular version of the standard solver (cbc) when you use the COIN_CMD solver

prob.solve(COIN_CMD(path = "C:/folder1/folder2/solver.xyz"))

hope this helps

Stu
On Fri, Nov 18, 2016 at 4:18 PM, Lucas Guido <guido...@gmail.com> wrote:
Dear gentlemen,

I modeled and programmed a LP with PuLP 1.6 over Python 3.5.2, working perfectly when I run the script. Nice!

Now my challenge is putting it in a EXE file, and for this I'm using PyInstaller. Here I have some trouble.
I receive the following error message when trying to run my EXE:

[...]
   File "site-packages\pulp\pulp.py", line 1643, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'
Failed to execute script myLP


My best guess is that compiled code don't have success on finding standard solver, so I need to manually point it in my code.
Am I right? How would I do it?

For me would be very interesting, if possible, not to install a solver or deal with environment variables. Best case would be download the solver and point the file inside the code (for example C:/folder1/folder2/solver.xyz).

Note 1: Code works perfecty when runed as script, including the solver. The problem happens only when I run it as EXE.
Note 2: The problem isn't numpy or related libraries, I already checked it out.

Please, light my path.

Tks in advance!
Lucas Guido

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.

Abdelmoghith El Belhadji

unread,
Feb 13, 2017, 4:11:15 PM2/13/17
to pulp-or-discuss

Wow,you rock Stu and Lucas!
Used your instructions to get Pulp to work with Cx_Freeze and, like you said, worked like a charm !
Thank's again !

drago...@gmail.com

unread,
Oct 20, 2017, 4:15:07 AM10/20/17
to pulp-or-discuss
Dear Abdelmoghith,

Could you post your steps?I also got similar problem.

I modeled over Pulp 1.6.8 and python 3.5.4, and pointed to an external cbc solver following Lucas's instruction,  it works well when i ran the script. 
When I tried to build a GUI executable with PyQt5.6.0 and PyInstaller3.2.1,  an exception occurred.
Then I changed the pack library to cx_Freeze, it worked, but when the model running, there will be cbc.exe console window flash through the screen, did you got similar situation? and do you know how to hide the console window? thx.


在 2017年2月14日星期二 UTC+8上午5:11:15,Abdelmoghith El Belhadji写道:

Abdelmoghith El Belhadji

unread,
Oct 27, 2017, 11:38:08 AM10/27/17
to pulp-or...@googlegroups.com
   Yeah, I had the same issue !
   The script ran smooth but when freezed, console windows were opened then closes everytime the solver was called... couldn't solve the issue and had to abandon.
    Good luck


--
You received this message because you are subscribed to a topic in the Google Groups "pulp-or-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pulp-or-discuss/3bS3KIc9-QM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.

Jason Lu

unread,
Oct 30, 2017, 3:28:53 AM10/30/17
to pulp-or-discuss
well, thank you for your response all the same.

在 2017年10月27日星期五 UTC+8下午11:38:08,Abdelmoghith El Belhadji写道:
To unsubscribe from this group and all its topics, send an email to pulp-or-discu...@googlegroups.com.

Jason Lu

unread,
Oct 30, 2017, 3:34:59 AM10/30/17
to pulp-or-discuss
Dear Stuart,

I modeled an ILP problem over Pulp 1.6.8 and python 3.5.4, and pointed to an external cbc solver following Lucas's instruction,  it works well when i ran the script. 
But after I built it to an executable using cx_Freeze, the cbc.exe console window will appear and close in a very short time when it being called. do you know how could i get rid of the cbc.exe console window? thx in advance.


在 2016年12月6日星期二 UTC+8上午4:21:04,Stuart Mitchell写道:
you can point to a particular version of the standard solver (cbc) when you use the COIN_CMD solver

prob.solve(COIN_CMD(path = "C:/folder1/folder2/solver.xyz"))

hope this helps

Stu
On Fri, Nov 18, 2016 at 4:18 PM, Lucas Guido <guido...@gmail.com> wrote:
Dear gentlemen,

I modeled and programmed a LP with PuLP 1.6 over Python 3.5.2, working perfectly when I run the script. Nice!

Now my challenge is putting it in a EXE file, and for this I'm using PyInstaller. Here I have some trouble.
I receive the following error message when trying to run my EXE:

[...]
   File "site-packages\pulp\pulp.py", line 1643, in solve
AttributeError: 'NoneType' object has no attribute 'actualSolve'
Failed to execute script myLP


My best guess is that compiled code don't have success on finding standard solver, so I need to manually point it in my code.
Am I right? How would I do it?

For me would be very interesting, if possible, not to install a solver or deal with environment variables. Best case would be download the solver and point the file inside the code (for example C:/folder1/folder2/solver.xyz).

Note 1: Code works perfecty when runed as script, including the solver. The problem happens only when I run it as EXE.
Note 2: The problem isn't numpy or related libraries, I already checked it out.

Please, light my path.

Tks in advance!
Lucas Guido

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.

Stuart Mitchell

unread,
Oct 30, 2017, 4:19:29 PM10/30/17
to pulp-or...@googlegroups.com
Hi I did have some code for this in previous versions, but removed it because it was causing problems.

Can I confirm that the window just opens and closes and the program works properly, and you want to get rid of the window?

Or is there some other problem?

Stu

To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to pulp-or-discuss@googlegroups.com.
Message has been deleted

Jason Lu

unread,
Nov 12, 2017, 9:39:13 PM11/12/17
to pulp-or-discuss
Thx  a lot for your response.
Yes, the program works properly, I just want to get rid of the console window of cbc.exe.
Could you give me some advices? thx
 
在 2017年10月31日星期二 UTC+8上午4:19:29,Stuart Mitchell写道:

jesper...@gmail.com

unread,
Aug 8, 2018, 7:26:48 AM8/8/18
to pulp-or-discuss
Hi Lucas and others,

The approach works as expected, and I am able to use CBC with Pyinstaller.
However, my solution times has increased significantly from 3.6 seconds in #2, to 43.5 seconds in #1.

Running both #1 and #2 in my normal python environment gives the same results. 

Any inputs why the solve times has increased?


   # 1
   import os
   cwd = os.getcwd()
   solverdir = 'cbc-2.7.5-win64\\bin\\cbc.exe'  # extracted and renamed CBC solver binary
   solverdir = os.path.join(cwd, solverdir)
   solver = pulp.COIN_CMD(path=solverdir)
   prob.solve(solver) # Function for execution of the model


    # 2
    prob.solve(PULP_CBC_CMD())


Additionally, using #1 is producing these files in solving process. Does this influence anything?

cfdb53e024664e67ab7341493a94be2f-pulp.mps
cfdb53e024664e67ab7341493a94be2f-pulp.sol



Thank you in advance.

Jesper Holm
M.Sc.Engineering
Message has been deleted

Stuart Mitchell

unread,
Aug 8, 2018, 7:34:02 AM8/8/18
to pulp-or...@googlegroups.com
Are you using the same version of cbc?

On Wed, 8 Aug 2018, 11:26 PM , <jesper...@gmail.com> wrote:
Dear All,

I have followed the instructions from Lucas and others, and it again works like a charm with Pyinstaller.

However, i do have a problem when accessing the solverdir and using pulp.COIN_CMD, my solve time increases enourmous.
This is the case even before I running pyinstaller on it. Running it through the .exe generated from pyinstaller returns slower solve times as well.

    # 1
    import os
    cwd = os.getcwd()
    solverdir = 'cbc-2.7.5-win64\\bin\\cbc.exe'  # extracted and renamed CBC solver binary
    solverdir = os.path.join(cwd, solverdir)
    solver = pulp.COIN_CMD(path=solverdir, threads=1, mip=1, options=['sec','500'], fracGap=0.1, msg=1)
    prob.solve(solver) # Function for execution of the model

# 1, returns an optimal solution in 43 seconds


Running it normally through python:
    # 2
    prob.solve(PULP_CBC_CMD(threads=1, mip=1, options=['sec','500'], fracGap=0.1, msg=1))

# 2, returns an optimal solution in 3 seconds.


How come things got slower? Any inputs?

Thank you in advance,

Jesper Holm
M.Sc. Engineering


torsdag den 22. december 2016 kl. 03.03.32 UTC+1 skrev Lucas Guido:

--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---

jesper...@gmail.com

unread,
Aug 8, 2018, 9:03:41 AM8/8/18
to pulp-or-discuss
Hi Stuart,

How embarrassing.

I follows the instructions from Lucas and 2.7.5 version, used the solverdir from pulp instead with version 2.9.0.
Solve times are back to normal and works beautiful with pyinstaller.

Thank you.
Reply all
Reply to author
Forward
0 new messages