Run Python from Processing. (Execute Python File)

Execute python from Processing How to run python file from processing. I tried Launch() already. It doesn't do anything. Then i tried exec and process builder. both throw me back with "Unhandled exception type IOException". Any help ?


  • And you are trying to do this in JavaScript Mode -- i.e. Processing.js or p5.js...?

  • The default mode. Not p5.js.

    This works when i wanted to open exe file. But I wanted to open a specific python file. void setup() { exec("C:/Windows/System32/notepad.exe"); }

    To simplify, I have a python file when run will generate a txt file as output. So I want processing to execute the python file and I should see the txt file made

  • edited October 2017

    Just describing the problem (as most folks sadly do in this forum) isn't enough.
    It should be accompanied by your runnable attempt as well! [-(

    Calling another programming language from another 1 isn't always as easy peasy.

    For example, take a look at this all big effort forum question to run Python from Processing: #:-S

    Each ".py" file can have any of these demands below so it can successfully run: 8-X

    1. Is Python properly installed in your system, w/ its PATH added too?
    2. Can you directly run Python by simply typing in python inside a terminal?
    3. Is your ".py" script file Python 2 or 3? Or is it compatible w/ both versions?
    4. Does your ".py" need to import any 3rd-party libraries? Are they already system-wide installed?
    5. Do you need to pass any file paths to your ".py" script?
    6. Or does your ".py" script already know where to get them?
    7. Does your ".py" script output any files which your Processing sketch needs to grab too?
    8. If so, that output folder is fixed or does it depends on Current Working Directory (CWD)?
    9. If it's dependent on CWD, you're gonna need to set it up somehow before running the ".py" script.
    10. I recommend you to use "" as alternative to both exec() or launch():
  • Firstly my apologize for not being more descriptive. I will take a note and be more descriptive from next time. :)

    Let me clarify one thing, When I want to execute a python file, I just double click on it and it runs. I was hoping to the same process but with the support of java. The process to just execute the python file (In more simple words, I want java to do the double click for me)

    1. yes Python is added to path.
    2. Yes. I can

    This is my python file

    f = open('Z.txt','w') f.write('hello world') f.close()

    1. It doesnt need to. I do plan on to. But thats the later stage. And there I plan to send via UDP.

    I got the IOException error removed.

    The following processing code works but I dont know how to open a python file and execute it.

    void setup() { Process p = exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/python.exe"); //Process p = exec("C:/Windows/System32/notepad.exe"); try { int result = p.waitFor(); println("the process returned " + result); } catch (InterruptedException e) { e.printStackTrace(); } }

    If I try with exec("C:/Users/Ramu/AppData/Local/Programs/Python/Python35/");

    it doesnt work

Sign In or Register to comment.