Executing .MPS or .LP file in Gurobi Shell Interactive
AnsweredGreaatings Dear Scientists,
I have written my model in a .lp and .mps format file, I need to execute my model on Gurobi Shell Interactive over university Labaratory. I dont know how! could you please help me
-
Hi Saeed,
Please note the interactive shell has been deprecated. As indicated by the article, the interactive shell is nothing more than a standard Python shell with the gurobipy namespace imported. So you may wish to use Python directly.
For now, you can still access this relevant tutorial: https://support.gurobi.com/hc/en-us/articles/14097607889041-Interactive-Shell-Tutorial-Reading-and-Optimizing-a-Model
Since your model has been written to file it may just be easier to use the gurobi command line. You can find a tutorial for this, and for using our APIs (including Python), here: https://support.gurobi.com/hc/en-us/articles/14799677517585-Getting-Started-with-Gurobi-Optimizer
- Riley
0 -
Thank you for your reply I see the error below. what can I do to resolve that.
m = read(r"C:/Users/sakbz/Desktop/FarmPlanning/VersonUploaded_03022025/effectivefarm.lp")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src\\gurobipy\\gurobi.pxi", line 3779, in gurobipy.read
File "src\\gurobipy\\gurobi.pxi", line 117, in gurobipy.gurobi.read
gurobipy.GurobiError: Unable to open file 'C:/Users/sakbz/Desktop/FarmPlanning/VersonUploaded_03022025/effectivefarm.lp' for input0 -
Hi Saeed,
The error message:
gurobipy.GurobiError: Unable to open file 'C:/Users/sakbz/Desktop/FarmPlanning/VersonUploaded_03022025/effectivefarm.lp' for input
suggests that Gurobi is unable to locate or access the file. Here are some possible reasons and solutions:
1. Check File Path
- Ensure that the file exists at the specified location:
C:/Users/sakbz/Desktop/FarmPlanning/VersonUploaded_03022025/effectivefarm.lp
- Try manually opening the file in a text editor or file explorer.
2. Correct the File Path Format
- If using Windows, try using double backslashes (
\\
) or raw strings (r"..."
) to avoid escape character issues:
ORm = read("C:\\Users\\sakbz\\Desktop\\FarmPlanning\\VersonUploaded_03022025\\effectivefarm.lp")
m = read(r"C:\Users\sakbz\Desktop\FarmPlanning\VersonUploaded_03022025\effectivefarm.lp")
3. Check File Permissions
- Ensure read permissions are granted for the file.
- If needed, right-click the file → Properties → Security → Edit Permissions → Allow "Read & Execute".
4. Check for Hidden Characters or Encoding Issues
- If the file was created or downloaded, try renaming it manually.
- Ensure it's saved in UTF-8 encoding (try opening it with a text editor like Notepad++).
5. Try Reading the File with Python
Run this script to check if Python can access the file:
try: with open(r"C:\Users\sakbz\Desktop\FarmPlanning\VersonUploaded_03022025\effectivefarm.lp", "r") as f: print("File is accessible.") except Exception as e: print(f"Error: {e}")
- If the script prints
"File is accessible."
, then Gurobi may not have permissions. - If an error occurs, double-check the file path and permissions.
- Bot
0 - Ensure that the file exists at the specified location:
-
Thank you so much Ray
It has been resolved with "r..." with backslash replacement.
0
Please sign in to leave a comment.
Comments
4 comments