Created
October 6, 2015 10:34
-
-
Save igniteflow/0b26441d3617dc344565 to your computer and use it in GitHub Desktop.
List python packages installed in a directory (such as with pip install --target my_dir)
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
import sys | |
import pkg_resources | |
""" | |
List python packages installed in a directory (such as with pip install --target my_dir) | |
python list-target.py /path/to/my_dir # can be relative or absolute | |
""" | |
try: | |
target_dir = sys.argv[1] | |
except IndexError: | |
print('ERROR: Pass the target_dir as an argument. e.g. python list-target.py my_dir') | |
exit(1) | |
print('Looking for packages in {} ...'.format(target_dir)) | |
env = pkg_resources.Environment([target_dir]) | |
dists = [] | |
for project in env: | |
for dist in env[project]: | |
dists.append("{}=={}".format(dist.project_name, dist.version)) | |
print('\n'.join(sorted(dists))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment