Reputation: 2802
I have a (Django) project with lots of imports that I started without virtualenv. Is there a way to
pip freeze
only the Python packages that are actually imported somewhere in the project, i.e. they are required by my project?
pip freeze
would list all the packages installed in my system, but I would only need those ones that are used by my project.
Upvotes: 2
Views: 934
Reputation: 439
A manual solution could be
Find the packages with grep
grep -r import ./*/*[.py] > j.t
Iterate all the lines in j.t
with python
fromIndex = line.find('from')
importIndex = line.find('import')
if fromIndex != -1:
return = line[fromIndex + 5 : importIndex - 1][5:]
else:
return = line[importIndex + 7:]
Remove all the duplicates
Pip freeze in the virtual env for find the version number
Pip freeze out the virtual env for find the other version number
Upvotes: 2