0

Using the simple instructions here https://www.metachris.com/2015/11/create-standalone-mac-os-x-applications-with-python-and-py2app/

I now have an app file in dist. However, when I open it, I get an alert saying nothing other than

App Error, Open Console or Terminate

My program is a python file that imports many modules (opencv, tkinter, and much more). When I run it from console (python app.py) it works great, opens my tkinter window, etc.

So firstly, what may be going wrong? And also, how is this actually supposed to work, does the app include all opencv too? How do python modules get included in a portable app like this?

Thanks for any help / guidance.

1 Answer 1

1

That's more than one Q!

Never mind.

  1. When you are building an app using Python interpreter provided by Apple you get semi-standalone application.

When such application is started it runs built-in Python from Apple and uses its standard library.

Any non-standard module should be included, but problems are often encountered.

  1. When you install your Python from python.org and all additional libs into it, then you proceed making app with it, instead with Apple's build of Python,

then whole interpreter is packed up, along with the standard lib, and anything else you imported.

This often works like a charm, although it produces much bigger apps. But now a days, its not such a catastrophy.

How does it work? py2app, py2exe and similar tools inspect the python code tree for import statements.

Then all dependencies found are included into the package.

Problematic part are dynamic imports that use import() or reload() function. For such modules you have to specifically tell py2app to package them.

Sometimes it is enough to add a static import to it in your app like:

if 0:
    import site

OpenCV, hm, I wish you luck! It brings living nightmares sometimes to properly link its paths for C++, I hope packaging it into app along with Python will work.

I do not use it, so I wouldn't know how much trouble are you in.

Use /Applications/Utilities/Console.app to see any errors and tracebacks sent to stderr/stdout after your app is packaged. You might find some useful info there.

But I'd advise you to download custom Python interpreter and make full standalone app. It's not a big deal. Just call setup.py with it instead with built-in one.

And search around on what you have to add to your setup.py to package OpenCV properly, if it is the cause of your trouble.

Sign up to request clarification or add additional context in comments.

5 Comments

This is really helpful - thanks. You are right OpenCv is a nightmare. I can't see this being easy. When you say download a custom python interpreter what do you mean in this case?
Well, you know, you may use any Python interpreter you like. Like one provided by Apple, CPython from python.org (that would be official Python distro), Jython and so on. You may build Python your self introducing changes you need or like. Custom in this sense. Because it is not one provided by OS. For you it'll be Python from python.org, nothing special. Just my clumsy expression. Sorry. Nightmare or not, everything can be done. Just be stubbern enough and you will succeed. :D
Completely agree with your attitude at the end their ;) couldn't be more accurate. On that note, after a few hours - finally managed to track down a few errors and found the modules of modules that were missing. Thanks for the advice regardless.
Let me guess. The module in question imports its submodules dynamically so py2app didn't find them. One additional advice: If you want to distribute your app, and still want semi-standalone application bundle, try it out on another machine to see whether it works. Don't take anything for granted.
Pretty much spot on - until py2app, all worked great - then had to import a sub module manually. Am going to try out on other machine asap. Cheers !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.