3

Is there any tool to generate requirements file based on actually used imports in your project, not only on output of pip freeze?

Rationale, as I see it:

it's nice and simple to generate requirements with pip freeze, when you start the project. Howether, when your project grows, you add some new dependecies, while other go away. It's already not very convinient to

pip freeze -r old_requirements > new_requirements

, as you already have some kind of tools installed into virtualenv, which are convinient, but are not needed for requirements (I'm talking about ipython or other such tools), so you have to correct requirements manually and clean them. Moreover, it's easy to forget to delete some library from requirements, when you project does not need it anymore, and a year later, you can't already remember, why it is there, and won't definetely delete it.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
eyeinthebrick
  • 528
  • 1
  • 5
  • 21

3 Answers3

3

I came across this https://github.com/bndr/pipreqs package, which does exactly, what I asked.

eyeinthebrick
  • 528
  • 1
  • 5
  • 21
1

I believe this is what you're looking for: https://pypi.python.org/pypi/findimports

DevLounge
  • 8,313
  • 3
  • 31
  • 44
-2

If you're on a *ix (or Cygwin), perhaps:'

cat *.py | egrep '^import' | sed -e 's/^import //' -e 's/#.*$//' -e 's/ *$//' | sort | uniq
user1277476
  • 2,871
  • 12
  • 10