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

Using a Bundler #297

Closed AidanNelson closed 4 months ago

AidanNelson commented 1 year ago

Hi @hx2A and all!

I'm so glad to be trying out py5. The docs are fantastic and my experience has been great so far.

I ran into a bit of an issue when trying to use pyInstaller to bundle my python / py5 script into executable file. The app bundled without error, but displayed the following error when trying to run the app:

  File "script.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
  File "py5/__init__.py", line 75, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 352, in exec_module
  File "py5/bridge.py", line 162, in <module>
  File "jpype/_jproxy.py", line 142, in JProxyCreator
  File "jpype/_jproxy.py", line 86, in _createJProxy
  File "jpype/_jproxy.py", line 51, in _prepareInterfaces
  File "jpype/_jproxy.py", line 162, in _convertInterfaces
  File "jpype/_jclass.py", line 99, in __new__
TypeError: Class py5.core.Py5Bridge is not found

I am on a Mac OS 13.1 System.

Are there any workarounds you know or best practices for bundling an app with py5?

Thanks, Aidan

hx2A commented 1 year ago

Welcome, @AidanNelson ! Good to hear from you. How have you been?

We are happy you are having a good experience with py5 and that you like the docs.

You didn't mention py5's PyInstaller docs. Did you read them? If not, they will help here. It seems like the jar files are either not included in the pyinstaller package or somehow the classpath is not including them.

I recommend packaging your Sketch into one directory first, before attempting to package it into a single executable file. Putting it in one directory will make it easier for you to debug and validate that the jar files are being included in the correct place. If you can get the package to work correctly for one directory, you will have solved all the py5-related problems and should have no trouble getting it to work in a single executable file.

The py5installer documentation isn't perfect. I think there are some Windows problems... @villares, that was your experience, right? If you can suggest ways to improve, please let us know!

Also, you know this is Jim, right? from ITP? We know each other IRL :)

AidanNelson commented 1 year ago

Hi Jim!

Yes, I knew it was you.

I was glad to see your recent update about the gallery show. Congratulations! 🎉

I've been well. Learning a bit of python has been a fun recent expedition. Would love to catch up properly one of these days.

Thanks for sending those docs. I hadn't seen those yet. I'll look them over and report back.

Hope all is well, Aidan

hx2A commented 1 year ago

I was glad to see your recent update about the gallery show. Congratulations! tada

Thank you!

I've been well. Learning a bit of python has been a fun recent expedition. Would love to catch up properly one of these days.

Great, glad you are doing well! Python is a fun language and I hope py5 makes it easy to learn. Are you looking at the introduction to py5 tutorials?

Thanks for sending those docs. I hadn't seen those yet. I'll look them over and report back.

I think they will be useful, even though they aren't perfect. If in your experiments you learn anything new about Py5Installer and py5, please make a PR to improve that page!

AidanNelson commented 1 year ago

Just did a bit of troubleshooting and found a few things (that may be somewhat specific to my system). I'll include them here in case anyone runs into these problems.

Other than that, things seemed to work smoothly!

And I'm jumping all around the reference. One feature that was particularly helpful for my application (which uses opencv-python) was the ability to generate a py5 image from a numpy array.

hx2A commented 1 year ago

@AidanNelson , I'm glad you have it working, and thanks for reporting back with what you figured out.

I read what you wrote and looked at the documentation. It seems there are two improvements we could make:

Do you think both of those changes would address the challenges you faced?

And I'm jumping all around the reference. One feature that was particularly helpful for my application (which uses opencv-python) was the ability to generate a py5 image from a numpy array.

Excellent! That is a useful feature. The numpy stuff was added to py5 early in its development.

If you like, I am happy to meet with you over Zoom to do a code review of your project. I might be able to point out other py5 features that will be useful to you.

AidanNelson commented 1 year ago

@hx2A

Re: the JRE, I think it was pulling JRE v.12. That said, I was a bit confused because homebrew had installed (but not linked) v.20, and I thought I was using v.20.

And I'm also surprised that it was trying to use the incorrect binary. No, I have a good old-fashioned Intel Mac.

The documentation was very helpful in both cases.

And thanks for offering about a code review. I may take you up on that once the project is a bit further along! I'm using multi-threading and passing images from another thread to py5 and there are some performance issues I'm trying to resolve at the moment.🙏

hx2A commented 1 year ago

And thanks for offering about a code review. I may take you up on that once the project is a bit further along! I'm using multi-threading and passing images from another thread to py5 and there are some performance issues I'm trying to resolve at the moment.

Using multi-threading and images with py5 is something I have a lot of experience with. I can definitely help out with that when you are ready. Just let me know

villares commented 1 year ago

Cheers, @AidanNelson and @hx2A, I wonder if you clever people who managed to make a PyInstaller bundle couldn't provide some sort of "template project" one could download, fiddle with, and "build"?

Could this project contain a Python interpreter one could pip or conda install additional packages to? I suppose we would have to have different templates for different platforms?

Does this idea make any sense?

PS: As Jim mentioned, I tried it on Windows a long time ago and I vaguely remember mixed results (like, it worked on one machine, but not in another) and I've been too unfocused to try anything that requires more than 3 neurons cooperating lately...

hx2A commented 1 year ago

Sorry for the late reply...

Haven't had any time to work with PyInstaller. There is the documentation page (https://py5coding.org/how_tos/pyinstaller.html) but you know about that and it is not perfect. It might work better on Linux, since I do most of my work there. Perhaps we can try to get a working template for linux, then figure out how to get it to work for the other platforms?

AidanNelson commented 1 year ago

Hi @villares and @hx2A, I did manage to get my project to build using pyInstaller, though I never quite figured out all of the kinks of building to Windows (I was developing on Mac for use on Windows).

Where do you think something like this should live? In the py5 examples repo?

villares commented 1 year ago

Oh, thanks folks!

Yes, let's try something minimal and grow slowly from it... Yes, I think the py5 examples repo would be a nice place to keep it!

hx2A commented 1 year ago

Thank you, @AidanNelson ! Can you also point out the deltas between what you learned about packaging and what is written on https://py5coding.org/how_tos/pyinstaller.html?

villares commented 1 year ago

I think I didn't remember the gist with the example files & spec file... I'll try it again, it might be just the kind of template I was thinking.

villares commented 4 months ago

Do you think we can close this @AidanNelson ? :)

Off topic: As you mentioned you are on MacOS, wouldn't you like to help us make some Thonny IDE Mac packages with py5 + JDK pre-installed?

villares commented 4 months ago

I'm going to close this. Feel free to re-open it if you wish, @AidanNelson !