eyeinthebrick
eyeinthebrick

Reputation: 548

Generate requirements based on used imports

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.

Upvotes: 4

Views: 1585

Answers (3)

eyeinthebrick
eyeinthebrick

Reputation: 548

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

Upvotes: 4

user1277476
user1277476

Reputation: 2909

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

cat *.py | egrep '^import' | sed -e 's/^import //' -e 's/#.*$//' -e 's/ *$//' | sort | uniq

Upvotes: -2

DevLounge
DevLounge

Reputation: 8437

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

Upvotes: 1

Related Questions