There are two tools such as 1) freeze and 2) pipreqs. However, freeze stores all packages in the environment of your code which might overinstall other ones that your code does not use. In contrast, pipreqs only stores the packages that are installed with pip install in your code environment.
$ pip install pipreqs
$ pipreqs /path/to/project