Find used python packages list needed to be installed (or used in requirements.txt)
grep -Rhs --color=never import . | awk '{print $2;}' | sort | uniq | xargs -I{} sh -c 'python -c "list(__import__(x) for x in filter(None, map(str.strip, '"'"'{}'"'"'.split('"'"','"'"'))))" 2>/dev/null || echo {}' |
GcsManager | |
Robot | |
WitInterface | |
WitResponse | |
XmppReporter | |
cjson | |
cloudsql | |
cloudsql.beans | |
cloudsql.dao | |
cloudsql.dao.dialogdao | |
cloudstorage | |
context | |
demoprotocol | |
dialogentrydao,historyentrydao,botuserdao | |
file | |
flask | |
flask.ext.babel | |
flask.json | |
flask_babel | |
geocoding | |
google.appengine._internal.django.utils | |
google.appengine.api | |
google.appengine.api.apiproxy_stub_map | |
google.appengine.api.app_identity | |
google.appengine.api.taskqueue | |
google.appengine.ext | |
google.appengine.ext.webapp | |
history | |
jsonpath_rw | |
langdetect | |
lazyawarejsonencoder | |
peewee | |
playhouse.shortcuts | |
plivogae | |
rtiprotocol | |
simplejson | |
smsinterface | |
spartanprotocol | |
speaklater | |
telegram | |
telegramInterface | |
tropointerface | |
twilio.twiml | |
useraddress | |
xmltodict | |
yaml |
This comment has been minimized.
This comment has been minimized.
Also this solution can be used as alias in ~/.profile file for use as a command in your #bash. Just drop these lines to your ~/.profile file and do _python_libraries () {
grep -Rhs --color=never import . | awk '{print $2;}' | sort | uniq | xargs -I{} sh -c 'python -c "list(__import__(x) for x in filter(None, map(str.strip, '"'"'{}'"'"'.split('"'"','"'"'))))" 2>/dev/null || echo {}'
}
alias python.libraries='_python_libraries' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Sometimes you getting dirty code where was not used requirements.txt file or you want to check code for dependencies (maybe your source code requires some libraries which are not installed in current virtualenv yet).
If you want to get python required python packages from scratch - create temporary virtualenv & activate it before running this code.
This short code features:
Try it! :)