How to find all imports placed in the code?

Viewed 57

Our project contains a lot of import statements inside class/function. That was the way to overcome cycle import issue at the moment. And for now we want to research and fix design issue behind it.

For that purposes I want to find all that places with imports in code.

  1. I have tried to search on "import" in Pycharm IDE and see imports not on the top of the file, but that does not show all this statements.

  2. Then I tried to use pep8, to find all E402 error(Module level import not at top of file), but that does not show all in function impots, that are most interesting

So my question is, how to find all that import that placed in code not in the file header?

1 Answers

Use pipreqs.

Running pipreqs with the default arguments will generate a requirements.txt for you.

$ pipreqs /home/project/location
Successfully saved requirements file in /home/project/location/requirements.txt
Related