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!

+1


a source to share


3 answers


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.

+1


a source


you must be able to extract the information you need from the so-called call schedule

See for example



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

+1


a source


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, not glob

    )) 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

    and re

    ), run the program, see which ones were created. Prerequisite: The user must have write access to the folder.
0


a source







All Articles