Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AdvancedHTMLParser (8.0.1)nappdirs (1.4.3)nbeautifulsoup4 (4.6.0)nchardet (3.0.4)nchrome-gnome-shell (0.0.0)ncupshelpers (1.0)ncycler (0.10.0)nCython (0.27.3)
- def get_installed_modules(self):
- data = subprocess.check_output(["pip", "list", "--local"])
- result = [tuple(line.replace('(', '').replace(')', '').split())
- for line in data.splitlines()]
- print(result)
- TypeError: a bytes-like object is required, not 'str'
- from pip.operations import freeze
- modules = list(
- map(lambda x: x.split('=='), freeze.freeze(local_only=True))
- )
- print(modules)
- [['aiodns', '1.1.1'],
- ['aiohttp', '1.2.0'],
- ['appdirs', '1.4.0'],
- ['appnope', '0.1.0'],
- ['argparse', '1.4.0'],
- ...
- import pip
- modules = []
- for i in pip.utils.get_installed_distributions():
- modules.append((i.key, i.version))
- print(modules)
- [('pytreebank', '0.2.4'),
- ('cssselect', '1.0.1'),
- ('numba', '0.36.0.dev0+92.g2818dc9e2'),
- ('llvmlite', '0.0.0'),
- ('yarl', '0.8.1'),
- ('xlwt', '1.3.0'),
- ('xlrd', '1.1.0'),
- ...
- ]
- import pip
- pip.main(['list', 'local'])
- >>> s = "AdvancedHTMLParser (8.0.1)nappdirs (1.4.3)nbeautifulsoup4 (4.6.0)nchardet (3.0.4)nchrome-gnome-shell (0.0.0)ncupshelpers (1.0)ncycler (0.10.0)nCython (0.27.3)"
- >>> re.findall(r"(.+) ((.+))", s)
- [('AdvancedHTMLParser', '8.0.1'),
- ('appdirs', '1.4.3'),
- ('beautifulsoup4', '4.6.0'),
- ('chardet', '3.0.4'),
- ('chrome-gnome-shell', '0.0.0'),
- ('cupshelpers', '1.0'),
- ('cycler', '0.10.0'),
- ('Cython', '0.27.3')]
- data = 'AdvancedHTMLParser (8.0.1)nappdirs (1.4.3)nbeautifulsoup4 (4.6.0)nchardet (3.0.4)nchrome-gnome-shell (0.0.0)ncupshelpers (1.0)ncycler (0.10.0)nCython (0.27.3)'
- result = [tuple(line.replace('(', '').replace(')', '').split())
- for line in data.splitlines()]
- print(result)
- [('AdvancedHTMLParser', '8.0.1'), ('appdirs', '1.4.3'), ('beautifulsoup4', '4.6.0'), ('chardet', '3.0.4'), ('chrome-gnome-shell', '0.0.0'), ('cupshelpers', '1.0'), ('cycler', '0.10.0'), ('Cython', '0.27.3')]
- self.__all_modules = [tuple(x[:-1].split(" (")) for x in data.splitlines()]
Add Comment
Please, Sign In to add comment