Collect all Python modules used in one folder?
Possible duplicate:
Build all Python modules used in one folder?
I don't think this has been asked before - I have a folder with many different .py files. script I've only used a few, but some name others and I don't know all used. Is there a program that will get everything it needs to make this script run in one folder?
Hooray!
Since Python is not a statically linked language, this task will be quite difficult. Especially if your code uses eval(...)
or exec(...)
.
If your script is not very big I would just pull it out, make sure your python.exe does not load modules from that directory and will run the script and add missing modules until it works.
You have multiple scenarios like this, then this manual work is not really the way to go. But in this case, having a lot of different .py files in the directory is not a good deployment technology and you should consider packing them into installable modules and installing them in your python site packages.
However, you can use the snakefood package to find our dependencies (already discussed here ). Again, it just may not be 100% accurate, but should give you an easy head start.
a source to share
you must be able to extract the information you need from the so-called call schedule
See for example
- http://pycallgraph.slowchop.com/ or
- http://blog.prashanthellina.com/2007/11/14/generating-call-graphs-for-understanding-and-refactoring-python-code/
In addition, py2exe converts the python call to an executable and in the process builds all the modules used. I think py2exe is cross platform
a source to share
I would try 2½ solutions, one tricky and 1½ quick and dirty:
- develop: custom import capture, log all imports
- quick and dirty, part a:
os.utime
* .py [co]? (re
notation, notglob
)) to have the access times yesterday, then run the program and collect all the latest access times. Prerequisite: The filesystem that marks the access time (itself and its mount options). - quick and dirty, part b: delete all * .py [co] files (same in the notation
glob
andre
), run the program, see which ones were created. Prerequisite: The user must have write access to the folder.
a source to share