1

Possible Duplicate:
Gather all Python modules used into one folder?

I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder?

Cheers!

Community
  • 1
  • 1

3 Answers3

1

Since Python is not statically linked language, this task would be rather a challenging one. Especially if some of your code uses eval(...) or exec(...).

If your script is not very big, I would just move it out, make sure that your python.exe does not load modules from that directory and would run the script and add missing modules until it works.

I you have multiple scripts like this, then this manual work is not really the way to go. But in this case also having lots of different .py files in a directory is not a good deployment technique and you should think about packaging them into installable modules and install into your python site-packages.

Still you may use snakefood package to find our the dependencies (has already been discussed here). Again, it just cannot be 100% accurate, but should give you an easy start.

Community
  • 1
  • 1
van
  • 74,297
  • 13
  • 168
  • 171
1

you should be able to extract the needed information from a so called call graph

See for example

Also, py2exe converts a python call into an executable and in this process it gathers all used modules. I think py2exe is cross platform

wires
  • 4,718
  • 2
  • 35
  • 31
0

I'd try 2½ solutions, one elaborate and 1½ quick-and-dirty:

  • elaborate: a custom import hook, logging all imports
  • quick and dirty, part a: os.utime the *.py[co]? (re notation, not glob) files to having access times of yesterday, then run the program and collect all recent access times. Prerequisite: a filesystem that marks access times (by itself and by its mount options).
  • quick and dirty, part b: remove all *.py[co] files (same in glob and re notation), run the program, see which have been created. Prerequisite: user should have write access to the folder.
tzot
  • 92,761
  • 29
  • 141
  • 204