How to list dependencies of a program (python)?

Keywords: python-3.x package anaconda


So I want to generate a summary of all packages used in a program along with the versions. Language: python

Suppose I have a program like

import numpy
import tensorflow
import pandas

Is there any command to automatically list all the packages I imported in THAT program (not all in the environment) along with their version? This is mainly because I use different environments, the versions are different and the imports are much more. It would be nice to keep it organized and pass this list of dependencies to the next person who will develop on this baseline.

Note: I don't want to do it manually using

conda list