Last active
March 17, 2016 19:59
-
-
Save phpdude/1cdb68de4be01c2dce9a to your computer and use it in GitHub Desktop.
Find used python packages list needed to be installed (or used in requirements.txt)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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 . ~/.profile
in current bash session to reload this file. After this you can use python.libraries
command in your bash session.
_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
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! :)