find required dependencies for a wxPython app (simply)

This is probably more a Python itself question than a wxPython one…anyway, here it is:

What’s the most convenient way to automatically get a list of all the modules/libraries that need to be installed on a computer in order for a wxPython application to work? I ask because I might try to have a (Mac-using) friend install the various libraries he’d need to try out a (Windows tested) program I’ll send him, but the list is kind of long and I’d like a definitive and automatically-generated list.

I could just laboriously go through and make the list myself, but I had a feeling there is probably a bit of code or a tool that would do this. I just really want output as stone simple as output like:

matplotlib 1.1

dateutil
Python 2.7
my_custom_module.py
etc…

py2exe does this implicitly, in that it finds everything needed to bundle the .exe, but doesn’t output a list for you. The point is, I want to just indicate one file, my main .py file, and then have it generate the list automatically.

Suggestions?

Thanks,
Che

Hi Che,

This is probably more a Python itself question than a wxPython one...anyway, here it is:

What's the most convenient way to automatically get a list of all the modules/libraries that need to be installed on a computer in order for a wxPython application to work? I ask because I might try to have a (Mac-using) friend install the various libraries he'd need to try out a (Windows tested) program I'll send him, but the list is kind of long and I'd like a definitive and automatically-generated list.

I could just laboriously go through and make the list myself, but I had a feeling there is probably a bit of code or a tool that would do this. I just really want output as stone simple as output like:

matplotlib 1.1
dateutil
Python 2.7
my_custom_module.py
etc...

py2exe does this implicitly, in that it finds everything needed to bundle the .exe, but doesn't output a list for you. The point is, I want to just indicate *one* file, my main .py file, and then have it generate the list automatically.

Suggestions?

Never used them but py2exe used modulefinder and I think py2app uses modulegraph.

A bit of googling on these two gives a few hits, so hopefully there is some stuff in here to help how to use these two, or maybe look in py2exe how it uses it.

Should you find something workable can you post it here.

Werner

···

On 16/04/2012 05:33, C M wrote:

Thanks,
Che
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi Che,

···

-----Mensaje original-----
De: Werner <werner.bruhin@sfr.fr>
Reply-to: wxpython-users@googlegroups.com
Para: wxpython-users@googlegroups.com
Asunto: Re: [wxPython-users] find required dependencies for a wxPython
app (simply)
Fecha: Mon, 16 Apr 2012 09:05:44 +0200

On 16/04/2012 05:33, C M wrote:

This is probably more a Python itself question than a wxPython
one...anyway, here it is:

What's the most convenient way to automatically get a list of all the
modules/libraries that need to be installed on a computer in order for
a wxPython application to work? I ask because I might try to have a
(Mac-using) friend install the various libraries he'd need to try out
a (Windows tested) program I'll send him, but the list is kind of long
and I'd like a definitive and automatically-generated list.

I could just laboriously go through and make the list myself, but I
had a feeling there is probably a bit of code or a tool that would do
this. I just really want output as stone simple as output like:

matplotlib 1.1
dateutil
Python 2.7
my_custom_module.py
etc...

py2exe does this implicitly, in that it finds everything needed to
bundle the .exe, but doesn't output a list for you. The point is, I
want to just indicate *one* file, my main .py file, and then have it
generate the list automatically.

Suggestions?
Never used them but py2exe used modulefinder and I think py2app uses
modulegraph.

A bit of googling on these two gives a few hits, so hopefully there is
some stuff in here to help how to use these two, or maybe look in py2exe
how it uses it.

Should you find something workable can you post it here.

Werner

Hi.

Test Pyinstaller.

Regards

Cris

Test Pyinstaller.

Thanks, but I don’t want to package anything; my friend has a Mac and I don’t, so I just want him to create the right environment so if I send him my .py files, they’ll run.

Che

It might be simplest to write the checks in yourself like so:

try:

import foo

except ImportError as e:

print e

Will produce “No module named foo”.

Or as a replacement method:

missing =

missing.append(imp(‘wx’))

missing.append(imp(‘gnuplot’))

for i in missing:

if i[0] == True:

print i[1]

end = 1

if end: exit()

def imp(module):

try:

exec("import "+module)

except ImportError as e:

return (True, str(e))

return (False, None)

Dirty, yes, but it does the job.

···

On Monday, 16 April 2012 22:33:13 UTC+2, Che M wrote:

Test Pyinstaller.

Thanks, but I don’t want to package anything; my friend has a Mac and I don’t, so I just want him to create the right environment so if I send him my .py files, they’ll run.

Che

Create a new virtualenv that has just the packages you need to run your app. When you get it set up and test that the application runs successfully, then you can run "pip freeze" to get a list of installed packages and their versions.

···

On 4/15/12 8:33 PM, C M wrote:

This is probably more a Python itself question than a wxPython
one...anyway, here it is:

What's the most convenient way to automatically get a list of all the
modules/libraries that need to be installed on a computer in order for a
wxPython application to work? I ask because I might try to have a
(Mac-using) friend install the various libraries he'd need to try out a
(Windows tested) program I'll send him, but the list is kind of long and
I'd like a definitive and automatically-generated list.

I could just laboriously go through and make the list myself, but I had
a feeling there is probably a bit of code or a tool that would do this.
I just really want output as stone simple as output like:

matplotlib 1.1
dateutil
Python 2.7
my_custom_module.py
etc...

py2exe does this implicitly, in that it finds everything needed to
bundle the .exe, but doesn't output a list for you. The point is, I
want to just indicate *one* file, my main .py file, and then have it
generate the list automatically.

Suggestions?

--
Robin Dunn
Software Craftsman

Hi Che,

Did you try gui2exe?

It has an option to show full build output - ctrl-f.

Run into issues with on wx 2.9.3, so only run it on 2.8 to check things as I haven't used for a long time (as I did not need a new setup).

Will document the problems with 2.9.3 in the next few days.

Werner

For finding modules, another option is a run-time check:

import sys

all_modules = sys.modules

then you can go through them, and see what is non standard, maybe by
looking at the __file__ attribute, etc.

I"ve often thought that I'd like py2exe, py2zpp and friends to do this
-- then you'd catch all the dynamically imported modules as well
(though maybe miss optional imported ones...)

-Chris

···

On Fri, Apr 20, 2012 at 12:42 AM, Werner <werner.bruhin@sfr.fr> wrote:

Hi Che,

Did you try gui2exe?

It has an option to show full build output - ctrl-f.

Run into issues with on wx 2.9.3, so only run it on 2.8 to check things as I
haven't used for a long time (as I did not need a new setup).

Will document the problems with 2.9.3 in the next few days.

Werner

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hmm, I didn’t know about that. Unfortunately, it’s way overkill–the output for my application has 1,137 lines!

I need something that will produce something more like 5-20 module names, maximum; just the 3rd party libraries (of which I use a handful or so) and the 10 or so modules that make up my application.

Che

···

On Fri, Apr 20, 2012 at 3:42 AM, Werner werner.bruhin@sfr.fr wrote:

Hi Che,

Did you try gui2exe?

It has an option to show full build output - ctrl-f.

I’m not sure you even need to create the virtualenv. The guy with the 2nd answer on Stack just used pip freeze: How do I get a list of locally installed Python modules? - Stack Overflow

  • Mike
···

On Thursday, April 19, 2012 4:04:32 PM UTC-5, Robin Dunn wrote:

On 4/15/12 8:33 PM, C M wrote:

This is probably more a Python itself question than a wxPython
one…anyway, here it is:

What’s the most convenient way to automatically get a list of all the
modules/libraries that need to be installed on a computer in order for a
wxPython application to work? I ask because I might try to have a
(Mac-using) friend install the various libraries he’d need to try out a
(Windows tested) program I’ll send him, but the list is kind of long and
I’d like a definitive and automatically-generated list.

I could just laboriously go through and make the list myself, but I had
a feeling there is probably a bit of code or a tool that would do this.
I just really want output as stone simple as output like:

matplotlib 1.1
dateutil
Python 2.7
my_custom_module.py
etc…

py2exe does this implicitly, in that it finds everything needed to
bundle the .exe, but doesn’t output a list for you. The point is, I
want to just indicate one file, my main .py file, and then have it
generate the list automatically.

Suggestions?
Create a new virtualenv that has just the packages you need to run your
app. When you get it set up and test that the application runs
successfully, then you can run “pip freeze” to get a list of installed
packages and their versions.


Robin Dunn
Software Craftsman
http://wxPython.org

I just looked at “dist” folder and in there at the “lib/library.zip”
looking at the folders in there gives some pretty good tips - also
it might have to much (just discovered that “mysql” stuff is in mine
which I don’t use).

Or use the 1,137 lines and have a little script "summarize it" by

folder name or something along these lines.

Did you try modulegraph?  In the doc there is a command line option

to the a .html instead of a list of modules.

Werner
···

http://packages.python.org/modulegraph/commandline.html

Right, but assuming you have more modules installed in your global python than the particular application needs (like most of us do) then you'll get extra stuff in that list. By creating a new environment and installing the bare minimum then you can get a minimal list and an environment to test in to make sure it works and that you have everything necessary added to the list.

···

On 4/20/12 1:41 PM, Mike Driscoll wrote:

    Create a new virtualenv that has just the packages you need to run your
    app. When you get it set up and test that the application runs
    successfully, then you can run "pip freeze" to get a list of installed
    packages and their versions.

    --
    Robin Dunn
    Software Craftsman
    http://wxPython.org

I'm not sure you even need to create the virtualenv. The guy with the
2nd answer on Stack just used pip freeze:
How do I get a list of locally installed Python modules? - Stack Overflow

--
Robin Dunn
Software Craftsman

Well, that’s certainly true. However, I thought getting wxPython into a virtualenv could be a pain? I haven’t tried it lately, but I know it was an issue a couple years ago.

  • Mike
···

On Friday, April 20, 2012 4:26:00 PM UTC-5, Robin Dunn wrote:

On 4/20/12 1:41 PM, Mike Driscoll wrote:

Create a new virtualenv that has just the packages you need to run your
app. When you get it set up and test that the application runs
successfully, then you can run "pip freeze" to get a list of installed
packages and their versions.

--
Robin Dunn
Software Craftsman
[http://wxPython.org](http://wxPython.org)

I’m not sure you even need to create the virtualenv. The guy with the
2nd answer on Stack just used pip freeze:
http://stackoverflow.com/questions/739993/unable-to-get-a-list-of-installed-python-modules

Right, but assuming you have more modules installed in your global
python than the particular application needs (like most of us do) then
you’ll get extra stuff in that list. By creating a new environment and
installing the bare minimum then you can get a minimal list and an
environment to test in to make sure it works and that you have
everything necessary added to the list.


Robin Dunn
Software Craftsman
http://wxPython.org

It's a pain on OSX because of how the Python it creates in the virtualenv is not really the Framework Python, but I've got a workaround on the wiki. For the others I just add a .pth file in the virtualenv that points to the wxPython-* folder in the master Python's site-packages dir.

···

On 4/20/12 2:37 PM, Mike Driscoll wrote:

On Friday, April 20, 2012 4:26:00 PM UTC-5, Robin Dunn wrote:

    On 4/20/12 1:41 PM, Mike Driscoll wrote:

     > Create a new virtualenv that has just the packages you need to
    run your
     > app. When you get it set up and test that the application runs
     > successfully, then you can run "pip freeze" to get a list of
    installed
     > packages and their versions.
     >
     > --
     > Robin Dunn
     > Software Craftsman
     > http://wxPython.org
     >
     > I'm not sure you even need to create the virtualenv. The guy with the
     > 2nd answer on Stack just used pip freeze:
     >
    How do I get a list of locally installed Python modules? - Stack Overflow
    <How do I get a list of locally installed Python modules? - Stack Overflow;
     >

    Right, but assuming you have more modules installed in your global
    python than the particular application needs (like most of us do) then
    you'll get extra stuff in that list. By creating a new environment and
    installing the bare minimum then you can get a minimal list and an
    environment to test in to make sure it works and that you have
    everything necessary added to the list.

Well, that's certainly true. However, I thought getting wxPython into a
virtualenv could be a pain? I haven't tried it lately, but I know it was
an issue a couple years ago.

--
Robin Dunn
Software Craftsman

virtualenv could be a pain? I haven’t tried it lately, but I know it was

an issue a couple years ago.

It’s a pain on OSX because of how the Python it creates in the virtualenv is not really the Framework Python, but I’ve got a workaround on the wiki. For the others I just add a .pth file in the virtualenv that points to the wxPython-* folder in the master Python’s site-packages dir.

Mike, if you are ever tempted to write a tutorial on your blog about how to go from zero to doing this on Windows, I’d be tempted to give it a try. At this point, though, by the time I’m halfway through figuring out how to get/install/use virtualenv, etc., I’ll have counted the modules manually, so it may not be worth my time right now.

Che

Hi Che,

···

On Friday, April 20, 2012 6:13:43 PM UTC-5, Che M wrote:

virtualenv could be a pain? I haven’t tried it lately, but I know it was

an issue a couple years ago.

It’s a pain on OSX because of how the Python it creates in the virtualenv is not really the Framework Python, but I’ve got a workaround on the wiki. For the others I just add a .pth file in the virtualenv that points to the wxPython-* folder in the master Python’s site-packages dir.

Mike, if you are ever tempted to write a tutorial on your blog about how to go from zero to doing this on Windows, I’d be tempted to give it a try. At this point, though, by the time I’m halfway through figuring out how to get/install/use virtualenv, etc., I’ll have counted the modules manually, so it may not be worth my time right now.

Che

I’ve been thinking about trying to figure this out. We’ll see. My time is rather limited lately though. I have a bunch of tutorials on the back burner at the moment and a book review or two as well.

  • Mike

I've been thinking about trying to figure this out. We'll see. My time is
rather limited lately though. I have a bunch of tutorials on the back
burner at the moment and a book review or two as well.

Thanks, Mike, for putting it on a back burner...in the meantime, here's
another tack, a simple one I found on SE (trying to re-find it now), that
maybe people could be interested in:

I put this at the end of my imports in my main file:

import sys
mods = sys.modules
for mod in mods.keys():
    print mod

In my case, this prints a 650 module long list of modules used. That's too
much for the aforementioned purpose, but the advantages of this to at least
start is that its clean and simple output. E.g., it looks like this:

matplotlib._tri
numpy.core.info
matplotlib.artist
ctypes.os
gc
matplotlib.tempfile
(etc....)

Now, I can imagine processing that list with Python somehow to pare it down
to something manageable. For example, all of the modules that are from the
Python standard library could be excluded, since that's not necessary to
provide in an environment. Also, all of the entries of the form
"library.submodule" could be reduced to just "library" (e.g. "
numpy.core.info" could be listed just as "numpy").

Lastly, if the developer adopts the convention of naming all the modules
for the app with a prefix, like "ML_" (for Media Locker, in your case),
then you could process these strings to separate those into a separate
list. (or maybe there's another way?). In the end, you'd get a nice list
like this:

matplotlib
numpy
ML_main
ML_database_stuff
datetime

A major weakness here is version numbers, though. Not sure how to address
that.

The reason I thought this approach (as opposed to the virtualenv one that
Robin gave) might be good for some is that it wouldn't require installing
anything, potentially acquiring it from Git or Mercurial, etc.... It would
be simple and newbie friendly.

Anyway, just thinking out loud.

Che

Hi Che,

I'll still give modulegraph a try, just installed it and run it against my app script with the following:

modulegraph.exe c:\dev\twcbv4\twcbsrc\controllers\app_cb.py >> h:\temp\twcbv4modgraph.txt

I then opened the .txt file (about 500 lines) in LibreOffice calc and told it to separate things on a fixed length and then sorted by the first column.

I then have groups of:
1. BuiltinModule
2. Extension
3. MissingModule
4. Package
5. Script
6. SourceModule

Inspecting these categories should get you close to what you need.

But it is not 100% perfect, e.g. I lately use Python's importlib to reduce the startup time a little (use it for all dialogs which are not used often, so instead of importing them at the beginning of the file they are dynamically imported when used, obviously something like modulegraph/py2exe and friends can't figure this out.

Werner