problem execute a python script #56
-
|
hi! pyCommunicator.run("import name_script"); String dia_st = String.valueOf(dia); Attempt attempt = pyCommunicator.runFile("name_script.name_func", dia_st,mes_st); When I execute the simulation in Anylogic, I obtain this message: "[Errno 2] No such file or directory". The script is in the same folder that the simulation... Thanks for everything! Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
the error is happening because the system cannot find the Python file path. make sure you used the .p extension (file.py) or it may be that the other file needs to be exported |
Beta Was this translation helpful? Give feedback.
-
|
try using the "subprocess" module import argparse def prediction(day, month): if name == "main": String day_st = String.valueOf(day); try { |
Beta Was this translation helpful? Give feedback.
-
|
The problem is that Attempt attempt = pyCommunicator.runResults("name_script.name_func(%s, %s)", dia, mes);
|
Beta Was this translation helpful? Give feedback.
The problem is that
runFileis only intended for non-interactive execution of scripts whereasrunandrunResultsare interactive. Because you imported the file withrun, you want to userunResultsinstead ofrunFile; you also don't need to convert them to (Java) string first, as the function will handle that for you.Note that if(I noticed your other comment shows it's expecting integers, so the code above is valid)name_funcis expecting those values as (Python) strings, you'll need to put single quotes around the string formatters (%s).