ronaldoussoren / py2app

py2app is a Python setuptools command which will allow you to make standalone Mac OS X application bundles and plugins from Python scripts.
Other
359 stars 36 forks source link

"No module" error when running "python setup.py py2app" #445

Open rickydaricky opened 2 years ago

rickydaricky commented 2 years ago

Almost certainly a me problem but I've tried reading the documentation and can't really figure out what to do.

When I run python setup.py py2app, my terminal gets to a line of: using recipe: autopackages *** {'packages': ['docutils', 'h5py', 'numpy', 'scipy', 'tensorflow']} despite none of my 5 scripts ever importing any of those libraries.

This quickly errors and tells me that No module named tensorflow.core.platform.lib_cpu_feature_guard.so_ccsharedlib.

How do I make sure that py2app isn't trying to import or use libraries that I don't actually need and never call? Does it have something to do with how I write my setup.py (I use the default) despite having multiple files in my program?

Thanks so much!

ronaldoussoren commented 2 years ago

The autopackages recipes tries to detect usage of a number of packages by looking in the dependency graph for the main script, and this found a number of dependencies.

It the script, and the list of installed packages, something you can share publicly?

rickydaricky commented 2 years ago

Thanks so much!

And yup – I've uploaded the code here: https://github.com/rickydaricky/wordle_solver.

I'm probably just be unfamiliar with dependency graphs, but I think what's happening is that my py2app command to build a standalone app is sourcing every library / package in my python environment instead of only those that I actually use in my code (and are shown in requirements.txt).

I'm still not sure how to specify that the only libraries I want py2app to include are the ones I explicitly import and have in my requirements.txt. Thanks again!

ronaldoussoren commented 2 years ago

I'll look at your code later, this is just a short explanation of how the dependency graph works.

The dependency graph is build using the modulegraph library that scans the (byte) code of Python modules for import statements. The graph builder starts at the main script of the app, and recursively looks at every module found in this way. Py2app's recipe system can update the graph (for example by adding known dependencies of C extensions, and removing dependencies that are known not to be used in general).

The scanner code shouldn't find any dependencies that aren't actually present in the code, but can find dependencies that aren't actually used (for example because library has optional support for some other library). That said, the scanner is software and all software has bugs...

rickydaricky commented 2 years ago

Thanks for the comment and explanation. I checked and it doesn't seem like any of those extraneous libraries are being called, imported, or used anywhere, but are nonetheless being picked up. Does py2app detect it as being used even if it's just in my python environment? Thanks!