Python Forum
to get a list of pip packages that were installed
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
to get a list of pip packages that were installed
#11
(Jun-23-2022, 10:41 PM)Skaperen Wrote: can it make a flat list of dependencies?
It will give new line display of using poetry show or can also use pip list when activate environment with poetry shell.
Poetry also gives description of what the libraries dos
G:\div_code\pan_env {git}{hg}
poetry show
atomicwrites    1.4.0  Atomic file writes.
attrs           21.4.0 Classes Without Boilerplate
colorama        0.4.5  Cross-platform colored terminal text.
more-itertools  8.13.0 More routines for operating on iterables, beyond itertools
numpy           1.23.0 NumPy is the fundamental package for array computing with Python.
packaging       21.3   Core utilities for Python packages
pandas          1.4.3  Powerful data structures for data analysis, time series, and statistics
pluggy          0.13.1 plugin and hook calling mechanisms for python
py              1.11.0 library with cross-python path, ini-parsing, io, code, log facilities
pyparsing       3.0.9  pyparsing module - Classes and methods to define and execute parsing grammars
pytest          5.4.3  pytest: simple powerful testing with Python
python-dateutil 2.8.2  Extensions to the standard Python datetime module
pytz            2022.1 World timezone definitions, modern and historical
six             1.16.0 Python 2 and 3 compatibility utilities
wcwidth         0.2.5  Measures the displayed width of unicode strings in a terminal
pip just list the libraries and version
G:\div_code\pan_env {git}{hg}
pip list
Package         Version
--------------- -------
atomicwrites    1.4.0
attrs           21.4.0
colorama        0.4.5
more-itertools  8.13.0
numpy           1.23.0
packaging       21.3
pandas          1.4.3
pip             22.0.3
pluggy          0.13.1
py              1.11.0
pyparsing       3.0.9
pytest          5.4.3
python-dateutil 2.8.2
pytz            2022.1
setuptools      60.6.0
six             1.16.0
wcwidth         0.2.5
wheel           0.37.1
To get Python list have to parse it,but i don't see why need that?
Can spend a couple of minute to make to a working Python list.
Redirect to a file pip list > "pip_lst.txt"
Parse it:
pip_lst = []
with open('pip_lst.txt') as f:
    next(f);next(f)
    for line in f:
        pip_lst.append(line.split())

print(pip_lst)
Output:
[['atomicwrites', '1.4.0'], ['attrs', '21.4.0'], ['colorama', '0.4.5'], ['more-itertools', '8.13.0'], ['numpy', '1.23.0'], ['packaging', '21.3'], ['pandas', '1.4.3'], ['pip', '22.0.3'], ['pluggy', '0.13.1'], ['py', '1.11.0'], ['pyparsing', '3.0.9'], ['pytest', '5.4.3'], ['python-dateutil', '2.8.2'], ['pytz', '2022.1'], ['setuptools', '60.6.0'], ['six', '1.16.0'], ['wcwidth', '0.2.5'], ['wheel', '0.37.1']]
Reply
#12
parsing that is easy enough. could you do pip_lst.append(line.split(None,1)[0]) to get a simpler list?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#13
(Jun-24-2022, 11:41 PM)Skaperen Wrote: could you do pip_lst.append(line.split(None,1)[0]) to get a simpler list?
Like this pip_lst.append(line.split()[0])
But when i think about should not use pip list in poetry,as get stuff that not need as pytest modules.
Like this.
poetry export --without-hashes --format=requirements.txt > requirements.txt
requirements.txt
numpy==1.23.0; python_version >= "3.10"
pandas==1.4.3; python_version >= "3.8"
python-dateutil==2.8.2; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.8"
pytz==2022.1; python_version >= "3.8"
six==1.16.0; python_version >= "3.8" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.8"
Then if need even simpler list don't known why this in needed all,parse like this.
poetry_lst = []
with open('requirements.txt') as f:
    for line in f:
        line = line.split('==')
        poetry_lst.append(line[0])

print(poetry_lst)
Output:
['numpy', 'pandas', 'python-dateutil', 'pytz', 'six']
So remember this is the modules Pandas need to run,as started with just a environment for Pandas poetry add pandas.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  what pip command can list installed files for a name package? Skaperen 3 2,155 Aug-04-2020, 10:15 PM
Last Post: Skaperen
  pip list available packages Skaperen 16 36,610 Oct-31-2017, 12:36 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020