py5coding / py5generator

Meta-programming project that creates the py5 library code.
https://py5coding.org/
GNU General Public License v3.0
52 stars 13 forks source link

Nothing append on macOS #71

Closed evayann closed 2 years ago

evayann commented 2 years ago

Setup : MacBook Air M1 16Go RAM Java 17 / Python 3.9

When I start a simple sketch, nothing append. I just have python logo on dock (see picture).

Capture d’écran 2022-03-25 à 21 09 16

If I force shutdown of program, I have this exception append (if it can help) :

Proxy called during shutdown
    at org.jpype.proxy.JPypeProxy.invoke(Unknown Source)
    at jdk.proxy2/jdk.proxy2.$Proxy7.run_method(Unknown Source)
    at py5.core.Sketch.draw(Sketch.java:188)
    at processing.core.PApplet.handleDraw(PApplet.java:2148)
    at processing.awt.PSurfaceAWT$9.callDraw(PSurfaceAWT.java:1440)
    at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:356)
Traceback (most recent call last):
  File "/Users/yannzavattero/Documents/Projects/RandomTest/test.py", line 9, in <module>
    py5.run_sketch()
  File "/opt/homebrew/lib/python3.9/site-packages/py5/__init__.py", line 20278, in run_sketch
    _py5sketch._run_sketch(functions, block, py5_options, sketch_args)
  File "/opt/homebrew/lib/python3.9/site-packages/py5/sketch.py", line 296, in _run_sketch
    while not surface.is_stopped() and not hasattr(self, '_shutdown_initiated'):
  File "/opt/homebrew/lib/python3.9/site-packages/py5/surface.py", line 88, in is_stopped
    return self._instance.isStopped()
jpype._core.JVMNotRunning: Java Virtual Machine is not running
hx2A commented 2 years ago

@evayann , thank you for the bug report.

py5 currently has some shortcomings on Mac computers. They are documented on the website: http://py5.ixora.io/content/osx_users.html

If you run this in a Jupyter notebook and execute %gui osx in the first cell, you should be able to run your example:

%gui osx

import py5

and then

def setup():
    py5.size(500, 500)

def draw():
    py5.circle(250, 250, 50)

py5.run_sketch()

The %gui osx command is a special magic command that activates an event loop that allows py5 to work on Mac computers. It is only available in Jupyter. It is not available when executing through a regular Python interpreter. Right now there is no way to run py5 in the regular Python interpreter, but this is something I want to make a priority for the future.

You can run py5 through the command line tool run_sketch. That does not involve Jupyter's magic command as it is doing something else.

However, I now see a number of new critical problems. First, if I leave out the %gui osx command, I see this message:

Importing py5 on OSX but the necessary Jupyter OSX event loop not been activated. I'll activate it for you, but next time, execute `%gui osx` before importing this library.

Which (1) has a grammar error and (2) doesn't actually activate the event loop. This is a new bug.

Second, I see that if I combine both of the above cells into 1 cell, it doesn't work. And third, if the first (and only the first) Sketch I try to run uses the P2D or P3D renderer, it doesn't work. Both of these are new bugs.

So, I have some work to do. Mac computers have caused a lot of headaches and I have more to deal with it seems. The truth is I didn't even have a Mac to test on for the first year of this project because of the pandemic, so it is a bit behind the other platfoms. Please bear with me as I work through these issues.

hx2A commented 2 years ago

@evayann Let's keep this open for now.

I now have a fix for this. Plus, I can now run py5 outside of Jupyter, which I've wanted to do for ages but haven't been able to get working until now. I still don't know what to do about the Apple Silicon issues and have some testing to do, but I am very happy with the progress I've made this weekend.

Aiming to do a new release in the next few weeks.

evayann commented 2 years ago

Nice job ! I wait your next feature to test it and make a feedback ! ^^

hx2A commented 2 years ago

Today's release of py5 should fix most (or all) of the OSX problems. Please read the rewritten Special Notes for OSX Users page and create a new issue if you see something that doesn't work. Thanks!