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

PythonCall not playing nicely with pyinstaller #248

Closed
KeithWM opened this issue Nov 26, 2022 · 8 comments
Closed

PythonCall not playing nicely with pyinstaller #248

KeithWM opened this issue Nov 26, 2022 · 8 comments

Comments

@KeithWM
Copy link

KeithWM commented Nov 26, 2022

First of all I'd like to express my appreciation for all the great work being done here. I think this package is a great facilitator for moving Julia out of it's initial niche towards integration into real, practical applications.

In that line, I've been trying to call Julia from a Python application that is then made into a (Windows) executable using pyinstaller. This did not work "out of the box". After a lot of digging, I discovered the bug was in the init_consts function, in particular in the evaluation of

:(pycopy!(pybuiltins.help, pybuiltinsmodule.help)), 

Commenting the :help in src/constants/consts.jl:66 gave a working application, much to my joy and that of my colleagues, but I don't know exactly why this helped, and if there's any downside to doing this. Even if my immediate problem has been resolved/avoided, I thought I should share what I found for the benefit of the community.

@cjdoris
Copy link
Collaborator

cjdoris commented Dec 1, 2022

Thanks for the report. It seems very odd indeed that that line would be the problematic one, but ok!

The downside of commenting out that line is that trying to use pybuiltins.help will likely crash your program horribly. Provided you don't use it you're good!

Do you have a MWE for this issue please? I have never used pyinstaller.

@KeithWM
Copy link
Author

KeithWM commented Mar 3, 2023

Sorry for not responding yet. It was a bit of a rush to get something delivered at the time, now I have some more time, I will see what I can share to illustrate the issue.

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 4, 2023

Looking at the help docs it looks like builtins.help is only available if site is imported, which pyinstaller presumably skips because it needs to control its own import path.

I can easily make that problematic line work by setting help=None if it's not available.

@cjdoris
Copy link
Collaborator

cjdoris commented Mar 10, 2023

I have fixed this on the main branch now, to appear in the next release. Thanks for the report.

@cjdoris cjdoris closed this as completed Mar 10, 2023
@KeithWM
Copy link
Author

KeithWM commented Mar 11, 2023

Just going to post a link to the commit for reference.

d223561

@MrHenning
Copy link

@KeithWM would you mind sharing how you managed to include juliacall in a PyInstaller app?
I am trying to do this on Linux, and I can't manage to get it to work.

Having an example (albeit on Windows) could still help! 🙂

@KeithWM
Copy link
Author

KeithWM commented Mar 25, 2024

I think the only thing I did was to comment the line src/constants/consts.jl:66 as mentioned in the original post. But I have the impression it has been solved now anyway. Sorry if that isn't enough help.

@MrHenning
Copy link

Thanks @KeithWM for answering 🙂
I actually meant how you handled the PyInstaller part.

In my minial build (on Linux) I have from juliacall import Main as jl, and when running the code it works, but trying to run the bundled app I get an error

ERROR: ArgumentError: Package PythonCall not found in current path.
- Run `import Pkg; Pkg.add("PythonCall")` to install the PythonCall package.

Do you do anything special in your PyInstaller command / .spec file? Including the julia binaries maybe?

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