# Sample code to create SVG file, using Processing 4.1.1 with Python mode

**URL:** https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828
**Category:** Processing.py
**Created:** [February 4, 2024, 4:54pm UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828 "2024-02-04T16:54:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![proc8888](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@proc8888](https://discourse.processing.org/u/proc8888)
#### Post date: [February 4, 2024, 4:54pm UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/1 "2024-02-04T16:54:24Z")

</div>

Hello,  
I would like to create an SVG file in Processing 4.1.1 Python mode  
but I am getting an error on this line: add\_library (‘svg’)  
Error:  
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader ‘bootstrap’)  
at jycessing.LibraryImporter.addJarToClassLoader(LibraryImporter.java:315)  
at jycessing.LibraryImporter.recursivelyAddJarsToClasspath(LibraryImporter.java:164)  
at jycessing.LibraryImporter.addLibrary(LibraryImporter.java:140)  
at jycessing.LibraryImporter$1. **call** (LibraryImporter.java:82)  
at org.python.core.PyObject. **call** (PyObject.java:480)  
at org.python.core.PyObject. **call** (PyObject.java:484)  
at org.python.pycode.\_pyx11.f$0(test\_svg\_240205.pyde:1)  
at org.python.pycode.\_pyx11.call\_function(test\_svg\_240205.pyde)  
at org.python.core.PyTableCode.call(PyTableCode.java:171)  
at org.python.core.PyCode.call(PyCode.java:18)  
at org.python.core.Py.runCode(Py.java:1614)  
at org.python.core.Py.exec(Py.java:1658)  
at org.python.pycode.\_pyx10.f$0…

There is an existing post in the forum saying to go back to Processing 3.5.4 as SVG works with this older version of Processing but unfortunately I have an error when I tried to revert back to this 3.5.4 older version. I get an error 'An error occurred during startup.

So it seems I’ve to stay with Processing 4.1.1.  
Appreciate if anyone has a sample code to create SVG file that works in Processing Python mode 4.1.1  
Much thanks.

---

<div class="post-metadata">

### Author: ![villares](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/villares/32/3166_2.png) [@villares](https://discourse.processing.org/u/villares)
#### Post date: [February 4, 2024, 8:29pm UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/2 "2024-02-04T20:29:01Z")

</div>

Hi @proc8888 !

I have been unable to make Python mode work with Processing 4.X ☹  
I can still run most Python mode sketches on Processing 3.5.4. Here are my SVG export [code examples](https://abav.lugaralgum.com/material-aulas/Processing-Python/exportando_svg.html)

Maybe you could try some [py5](https://py5coding.org)? My [sample code for py5](https://abav.lugaralgum.com/material-aulas/Processing-Python-py5/exportando_svg.html)

---

<div class="post-metadata">

### Author: ![proc8888](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@proc8888](https://discourse.processing.org/u/proc8888)
#### Post date: [February 4, 2024, 10:56pm UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/3 "2024-02-04T22:56:01Z")

</div>

Thank you for update and sample code for py5

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2024, 1:09am UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/4 "2024-02-05T01:09:32Z")

</div>

> [@proc8888](#):
>
> I have an error when I tried to revert back to this 3.5.4 older version.

Recently I’ve moved my “processing-3.5.4” app folder from a Win 8.1 laptop to another 1 w/ Win 10 and it works the same.

However, b/c you also have Processing 4, you’re gonna need to have separate sketchbook folders for both P3 & P4.

Here’s a way to do it on Windows:

- 1st, close all running Processing instances, so they won’t overwrite the “preferences.txt” file we’re gonna edit later.

- Go to folder `%USERPROFILE%\Documents` and create a subfolder named `code` or another name of your liking.

- inside subfolder `code`, create 2 subfolders; 1 for “Processing 3” and another for “Processing 4”.

- BtW, in my laptop I’ve got 4 subfolders named: `P1`, `P2`, `P3`, `P4`. B/c I’ve got all Processing versions!

- Annotate the path of those folders b/c we’ll need them in this next 2nd step.

- It’s very important to have separate sketchbooks for each of those major versions due to library incompatibility among them.

- Now go to folder `%APPDATA%\Processing` and open the “preferences.txt” file there using some text editor, like Notepad.

- Go to the bottom of “preferences.txt” and try to find these 3 entries:

- Those 3 entries represent the paths of our sketchbook folders for Processing versions 2, 4 and 3 respectively.

- Use the paths you’ve annotated earlier on those config entries and save the file.

If you’ve followed those instructions right, each Processing major version will use its own sketchbook, so libraries installed for 1 major version won’t crash the other.

P.S.: You can move the contents of the sketchbook folder your “Processing 4” was using to its newest folder.

However, only your own sketches, not the subfolders `libraries`, `modes` nor `tools`; b/c it can happen they already contain mixed versions of both Processing 3 & 4 inside them!

---

<div class="post-metadata">

### Author: ![proc8888](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@proc8888](https://discourse.processing.org/u/proc8888)
#### Post date: [February 5, 2024, 1:24am UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/5 "2024-02-05T01:24:51Z")

</div>

Hello @GoToLoop Thank you for shedding further further light on this. I’ll ‘map’ your suggestions to MAC version, which I’m using. Very useful info., appreciated.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 5, 2024, 1:32am UTC](https://discourse.processing.org/t/sample-code-to-create-svg-file-using-processing-4-1-1-with-python-mode/43828/6 "2024-02-05T01:32:08Z")

</div>

Just asked Bing AI for those Windows paths when they’re ‘mapped’ to Mac:

1. `%USERPROFILE%\Documents\` → `~/Documents/`
2. `%APPDATA%\Processing\` → `~/Library/Processing/`

Not sure if any of them is correct though.

P.S.: When you need to change from Processing 4 to Processing 3 and vice-versa, remember to close the current 1 before opening the other!
