[TUTORIAL]Running Python Mode in VScode

This is the method that I used to get processing.py sketches to run in VScode.

You will need:

  • Java to be installed and added to path
  • The file processing-py.jar
  • The Code runner extension

To get the first two items refer to the tutorial on how to run processing.py sketches on the command line here.

  1. Open up a new workspace and create a python file with the processing code you want to run.
    Example code:
# mouse_follow.py
def setup():
    size(400,400)

def draw():
    background(255)
    fill(0)
    ellipse(mouseX, mouseY, 50, 50)
  1. Add the processing-py.jar file in the same workspace.
  2. In the settings.json file under WORKSPACE SETTINGS tab, add the line:
 "code-runner.customCommand": "java -jar processing-py.jar mouse_follow.py"

So it should look something like this:

{
    "code-runner.customCommand": "java -jar processing-py.jar mouse_follow.py"
}
  1. Run the command Run Custom Command (Ctrl + Alt + K)
  2. Bask in the glory of your work.

NB: The file processing-py.jar can be located anywhere just add its path to the custom command.

Let me know if you get stuck on any part of this, I will try to help you.
No, Thankyou!

10 Likes

Thank you so much for creating this!

1 Like

very nice! I’m doing a presentation about creative coding with Python and this will be very useful, thanks for sharing!

2 Likes

I was wondering if anyone starting Processing from VS Code or from the command line know how to control the location of the Processing application? I’m running in two screens, and I’d like to set where the sketch will show up on the screen after launch.

I have not tested it (because I don’t have a second monitor right now), but see if fullscreen() would help:

https://py.processing.org/reference/fullScreen.html

fullScreen()
fullScreen(display)
fullScreen(renderer)
fullScreen(renderer, display)

Known issues: https://github.com/jdf/processing.py/issues/346

1 Like

hi I got an error as this:

[Running] java -jar processing-py.jar mouse_follow.py

‘java’ is not recognized as an internal or external command,

operable program or batch file.

and i have no idea what to do, would you help me?

Have you added the Java path to your system variables?
https://www.java.com/en/download/help/path.xml

I’ve mentioned this thread on an issue: https://github.com/TobiahZ/processing-vscode/issues/79
So I’m linking it in case someone back here has the skills to contribute to the VS Code extension…

1 Like

So … I decided to try it out :smiley:
But it didn’t work for me at first :confused:

So, for me the workspace thing didn’t work, but this extension settings thing did work!
(maybe I have the wrong extension?!?!?!)


:slight_smile:

1 Like

Hi, tbh its been so long that I don’t remember how this works.
However since then I’ve moved onto use p5py a pure python implementation of processing which means you don’t have to fiddle around with java or extensions (Although you do have to get glfw which took me a while).

After using p5py for a while I realised there was pretty slow and a lot of overhead in how it worked. So I made my own implementation built on top of pyglet. I haven’t made it public yet as I got distracted by other projects but if someone wants to try it give me a push.

1 Like

How cool! I’d love to see that!

I have been dabbling with flat (a Python library) which is good for print/static/SVG stuff, but not animations/interactions.

2 Likes

I would be very interested in seeing your pyglet implementation!

1 Like

Hokay I’ve done the repo up a bit, made it public and announced it on a seperate topic. Go knock yourselves out and break it pls.


3 Likes

Thanks for sharing this, @fenjalien! I’ve moved your announcement post into our new p5py category.

1 Like

how can i use igeo library(http://igeo.jp/) in vs code?

Hi @Mayarch

If you have processing.py working in VScode (as per @fenjalien and @villares’ instructions), then you can add libraries (igeo, etc.) using these instructions: https://py.processing.org/tutorials/command-line/#processing-libraries

1 Like

i can use processing.py in vs code as native.but when i try to use third part libraries like igeo,even if i followed the instructions in the link that u send,i couldn t success to reach i geo library in vs code.

when i try to add pdf library i took that messages.

It seems that the command line version doesn’t include the PDF library – but you can copy this across from a standard Processing install.

I got the same iGeo errors as you, so this isn’t a VScode issue. However, I got this example working fine:

#from java.lang import System
#System.setProperty("jogl.disable.openglcore", "false")

add_library('igeo')

def setup():
    size(480, 360, IG.GL)

def draw():
    IPoint(0,0,0)
    IPoint(20,0,0)
    IPoint(20,20,0)
    IPoint(0,20,0)

Uncomment the first two lines for Linux.

1 Like

one more question . is there anyway to use autocomplete for igeo command_?