-1

The script I am using for solving LPP is following:

Script:

# Import PuLP modeler functions
from pulp import *
# Create the 'prob' variable to contain the problem data
prob = LpProblem("The Whiskas Problem",LpMinimize)
LpVariable("example", None, 100)
# The 2 variables Beef and Chicken are created with a lower limit of zero
x1=LpVariable("ChickenPercent",0,None,LpInteger)
x2=LpVariable("BeefPercent",0)
# The objective function is added to 'prob' first
prob += 0.013*x1 + 0.008*x2, "Total Cost of Ingredients per can"
# The five constraints are entered
prob += x1 + x2 == 100, "PercentagesSum"
prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement"
prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement"
prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement"
prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"
# The problem data is written to an .lp file
prob.writeLP("WhiskasModel.lp")
# The problem is solved using PuLP's choice of Solver
prob.solve()
# The status of the solution is printed to the screen
print( "\n", "Status:", LpStatus[prob.status],"\n")
# Each of the variables is printed with it's resolved optimum value
for v in prob.variables():
print( v.name, "=", v.varValue)
# The optimised objective function value is printed to the screen
print ("Total Cost of Ingredients per can = ", value(prob.objective))

Question:In output I am getting error related to pulp, what modifications should in this code to get the correct output?

output:

ImportError                               Traceback (most recent call last)
<ipython-input-17-35d0a00262fe> in <module>()
      1 # Import PuLP modeler functions
----> 2 from pulp import *
      3 # Create the 'prob' variable to contain the problem data
      4 prob = LpProblem("The Whiskas Problem",LpMinimize)
      5 LpVariable("example", None, 100)

ImportError: No module named 'pulp'
chunky
  • 75
  • 1
  • 2
  • 11

1 Answers1

1

You've not installed pulp

Make sure you've run either:

pip install pulp

or

pip3 install pulp 

based on whatever Python Kernel version you're running in Jupyter or iPython Notebooks. If you've got a virtual environment set up, make sure you've run the Jupyter installation in the virtual env.

Additionally, PuLP has some base dependencies that may be missing from your system. To check whether you have everything set up correctly, run:

>>> import pulp
>>> pulp.pulpTestAll()

You should see a list of missing dependencies (if any) that could be stopping the module from installing/importing.

SashaZd
  • 3,315
  • 1
  • 26
  • 48