Guest User

Untitled

a guest
Dec 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. 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)
  2.  
  3. def get_installed_modules(self):
  4. data = subprocess.check_output(["pip", "list", "--local"])
  5. result = [tuple(line.replace('(', '').replace(')', '').split())
  6. for line in data.splitlines()]
  7. print(result)
  8.  
  9. TypeError: a bytes-like object is required, not 'str'
  10.  
  11. from pip.operations import freeze
  12.  
  13. modules = list(
  14. map(lambda x: x.split('=='), freeze.freeze(local_only=True))
  15. )
  16.  
  17. print(modules)
  18.  
  19. [['aiodns', '1.1.1'],
  20. ['aiohttp', '1.2.0'],
  21. ['appdirs', '1.4.0'],
  22. ['appnope', '0.1.0'],
  23. ['argparse', '1.4.0'],
  24. ...
  25.  
  26. import pip
  27.  
  28. modules = []
  29. for i in pip.utils.get_installed_distributions():
  30. modules.append((i.key, i.version))
  31.  
  32. print(modules)
  33.  
  34. [('pytreebank', '0.2.4'),
  35. ('cssselect', '1.0.1'),
  36. ('numba', '0.36.0.dev0+92.g2818dc9e2'),
  37. ('llvmlite', '0.0.0'),
  38. ('yarl', '0.8.1'),
  39. ('xlwt', '1.3.0'),
  40. ('xlrd', '1.1.0'),
  41. ...
  42. ]
  43.  
  44. import pip
  45. pip.main(['list', 'local'])
  46.  
  47. >>> 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)"
  48. >>> re.findall(r"(.+) ((.+))", s)
  49. [('AdvancedHTMLParser', '8.0.1'),
  50. ('appdirs', '1.4.3'),
  51. ('beautifulsoup4', '4.6.0'),
  52. ('chardet', '3.0.4'),
  53. ('chrome-gnome-shell', '0.0.0'),
  54. ('cupshelpers', '1.0'),
  55. ('cycler', '0.10.0'),
  56. ('Cython', '0.27.3')]
  57.  
  58. 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)'
  59. result = [tuple(line.replace('(', '').replace(')', '').split())
  60. for line in data.splitlines()]
  61.  
  62. print(result)
  63.  
  64. [('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')]
  65.  
  66. self.__all_modules = [tuple(x[:-1].split(" (")) for x in data.splitlines()]
Add Comment
Please, Sign In to add comment