Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a Bundler #297

Closed
AidanNelson opened this issue Jun 1, 2023 · 15 comments
Closed

Using a Bundler #297

AidanNelson opened this issue Jun 1, 2023 · 15 comments

Comments

@AidanNelson
Copy link

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
Copy link
Collaborator

hx2A commented Jun 1, 2023

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
Copy link
Author

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
Copy link
Collaborator

hx2A commented Jun 1, 2023

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
Copy link
Author

AidanNelson commented Jun 1, 2023

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.

  • I had two versions of the Java JDK. One had been installed in the standard location and was version 12. Another was installed using homebrew and was version 20. In order to fix the PyInstaller build, I had to include the correct version (from homebrew). For me, this meant including the following line in my pyInstaller spec file: datas += [('/usr/local/Cellar/openjdk/20.0.1/libexec/openjdk.jdk', 'JAVA_HOME')]

  • For some reason, I kept getting an error when using binaries += collect_dynamic_libs('py5') which seemed like it was trying to run the linux binary. Only including the Mac OS binaries with binaries += filter(lambda x: x[1].split('/')[2] in ["macos-x86_64"], collect_dynamic_libs('py5')) fixed this.

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
Copy link
Collaborator

hx2A commented Jun 1, 2023

@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:

  • In the Java Runtime Environment section, we should mention that including the JRE in the package might be necessary, as jpype might not be able to find the correct JRE without it. BTW, was it finding the version 12 JRE, or was it not finding either JRE?
  • I'm surprised it was trying to run the linux binary. Do you have one of the new M1 Mac machines? In any case, in the py5 section, we should say that the described filtering might be necessary. We should also probably list those weird codes "macos-x86_64", "windows-amd64", etc, since not everyone will be familiar with them or even know which one applies to their situation.

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
Copy link
Author

@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
Copy link
Collaborator

hx2A commented Jun 6, 2023

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
Copy link
Collaborator

villares commented Aug 12, 2023

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
Copy link
Collaborator

hx2A commented Aug 21, 2023

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
Copy link
Author

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
Copy link
Collaborator

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
Copy link
Collaborator

hx2A commented Aug 21, 2023

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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants