用python写代码:pip list,列出:pip install 库1 库2库3...,方便一次性安装

彻底解决pip安装库问题

用python写代码:pip list
列出:pip install 库1 库2 库3 这种输出

以下是使用Python编写代码来实现类似pip listpip install package1 package2 package3输出的示例:

import pkg_resources

# 列出已安装的包和版本
installed_packages = [p for p in pkg_resources.working_set]
for package in installed_packages:
    print(f"{package.project_name} ({package.version})")

# 安装指定的包
packages_to_install = ["package1", "package2", "package3"]
for package in packages_to_install:
    try:
        pkg_resources.get_distribution(package)
        print(f"{package} is already installed")
    except pkg_resources.DistributionNotFound:
        print(f"Installing {package}...")
        # 执行安装命令,这里只是模拟输出
        print(f"Successfully installed {package}")

上述代码中,我们使用了pkg_resources模块来获取已安装的包列表并显示其名称和版本。然后,我们遍历要安装的包列表,并检查每个包是否已经安装。如果已经安装,则显示相应信息;否则,输出安装命令的模拟结果。

请注意,这只是一个简单的演示代码,实际执行安装命令需要使用适当的方法,例如使用subprocess模块来执行命令行安装命令。

/data/user/0/org.qpython.qpy/files/bin/qpy thon3.sh "/storage/emulated/0/qpython/数据 点1.1.1.py" && exit
python/数据点1.1.1.py" && exit           < certifi (2023.7.22)
pytz (2022.6)
setuptools (65.5.0)
pyzmq (24.0.1)
pip (22.3.1)
attrs (22.1.0)
argon2-cffi (21.3.0)
packaging (21.3)
argon2-cffi-bindings (21.2.0)
virtualenv (20.24.5)
Faker (19.6.1)
clang (16.0.1.1)
rich (13.5.2)
Pillow (9.3.0)
mss (9.0.1)
ipython (8.6.0)
tenacity (8.2.3)
click (8.1.7)
ipywidgets (8.0.2)
jupyter-client (7.4.4)
nbconvert (7.2.3)
ipykernel (6.17.0)
importlib-metadata (6.8.0)
notebook (6.5.2)
jupyter-console (6.4.4)
tornado (6.2)
ftfy (6.1.1)
cowsay (6.0)
plotly (5.16.1)
psutil (5.9.3)
nbformat (5.7.0)
traitlets (5.5.0)
qtconsole (5.4.0)
bleach (5.0.1)
dash-table (5.0.0)
tqdm (4.66.1)
fonttools (4.38.0)
jsonschema (4.17.0)
jupyter-core (4.11.2)
selenium (4.11.2)
beautifulsoup4 (4.11.1)
lxml (4.9.1)
pexpect (4.8.0)
typing-extensions (4.7.1)
decorator (4.4.2)
widgetsnbextension (4.0.3)
simplejson (3.19.1)
zipp (3.16.2)
filelock (3.12.4)
platformdirs (3.10.0)
prettytable (3.8.0)
anyio (3.6.2)
matplotlib (3.6.1)
Markdown (3.4.4)
idna (3.4)
charset-normalizer (3.2.0)
XlsxWriter (3.1.3)
Jinja2 (3.1.2)
openpyxl (3.1.2)
networkx (3.1)
pyscreenshot (3.1)
prompt-toolkit (3.0.32)
pyparsing (3.0.9)
jupyterlab-widgets (3.0.3)
colorcet (3.0.1)
markdown-it-py (3.0.0)
ExifRead (3.0.0)
pyttsx3 (2.90)
imageio (2.31.2)
requests (2.31.0)
pycparser (2.21)
fastjsonschema (2.16.2)
Pygments (2.13.0)
dash (2.12.1)
Babel (2.12.1)
anytree (2.9.0)
python-dateutil (2.8.2)
emoji (2.8.0)
scapy (2.5.0)
sortedcontainers (2.4.0)
soupsieve (2.3.2.post1)
gTTS (2.3.2)
termcolor (2.3.0)
Flask (2.2.5)
Werkzeug (2.2.3)
QtPy (2.2.1)
itsdangerous (2.1.2)
MarkupSafe (2.1.1)
asttokens (2.1.0)
SciencePlots (2.1.0)
rembg (2.0.50)
mistune (2.0.4)
urllib3 (2.0.4)
pyecharts (2.0.3)
pyMd2Doc (2.0.2)
dash-html-components (2.0.0)
dash-core-components (2.0.0)
cleverbot (2.0.0)
mutagen (1.46.0)
numpy (1.23.4)
jupyter-server (1.21.0)
six (1.16.0)
cffi (1.15.1)
param (1.13.0)
sympy (1.12)
pyperclip (1.8.2)
Send2Trash (1.8.0)
ansi2html (1.8.0)
PySocks (1.7.1)
treelib (1.7.0)
debugpy (1.6.3)
blinker (1.6.2)
nest-asyncio (1.5.6)
pandas (1.5.1)
pandocfilters (1.5.0)
kiwisolver (1.4.4)
pystacker (1.4.4)
websocket-client (1.4.2)
pydot (1.4.2)
ffmpeg (1.4)
docxcompose (1.4.0)
install (1.3.5)
retrying (1.3.4)
sniffio (1.3.0)
mpmath (1.3.0)
arrow (1.2.3)
tinycss2 (1.2.1)
executing (1.2.0)
outcome (1.2.0)
XMind (1.2.0)
wsproto (1.2.0)
schedule (1.2.0)
exceptiongroup (1.1.3)
et-xmlfile (1.1.0)
EasyProcess (1.1)
entrypoint2 (1.1)
xmindparser (1.0.9)
PyMsgBox (1.0.9)
pytweening (1.0.7)
contourpy (1.0.6)
moviepy (1.0.3)
pyfiglet (1.0.2)
jupyter (1.0.0)
pypinyin (0.49.0)
jieba (0.42.1)
wheel (0.38.2)
pydub (0.25.1)
trio (0.22.2)
graphviz (0.20.1)
pyrsistent (0.19.2)
future (0.18.3)
jedi (0.18.1)
EbookLib (0.18)
terminado (0.17.0)
schemdraw (0.17)
docxtpl (0.16.7)
prometheus-client (0.15.0)
python3-xlib (0.15)
h11 (0.14.0)
pyqtgraph (0.13.3)
bottle (0.12.23)
cycler (0.11.0)
trio-websocket (0.10.3)
PyAutoGUI (0.9.54)
tabulate (0.9.0)
python-docx (0.8.11)
parso (0.8.3)
jeepney (0.8.0)
pickleshare (0.7.5)
defusedxml (0.7.1)
nbclient (0.7.0)
ptyprocess (0.7.0)
mplcyberpunk (0.7.0)
stack-data (0.6.0)
pyjokes (0.6.0)
webencodings (0.5.1)
pyct (0.5.0)
nbclassic (0.4.8)
imageio-ffmpeg (0.4.8)
entrypoints (0.4)
pytesseract (0.3.10)
matplotx (0.3.10)
termplotlib (0.3.9)
dill (0.3.7)
distlib (0.3.7)
textrank4zh (0.3)
wcwidth (0.2.5)
jupyterlab-pygments (0.2.2)
notebook-shim (0.2.2)
pure-eval (0.2.2)
backcall (0.2.0)
ipython-genutils (0.2.0)
PyRect (0.2.0)
ffmpeg-python (0.2.0)
PyScreeze (0.1.29)
proglog (0.1.10)
matplotlib-inline (0.1.6)
qbstyles (0.1.4)
MouseInfo (0.1.3)
mdurl (0.1.2)
ffprobe3 (0.1.2)
tk (0.1.0)
mindmap (0.0.65)
cyberpunk-theme (0.0.14)
PyGetWindow (0.0.9)
apigptcloud (0.0.9)
tkstyle (0.0.6)
snapshot-selenium (0.0.2)
py2flowchart (0.0.2)
flowchart (0.0.1)
Installing package1...
Successfully installed package1
Installing package2...
Successfully installed package2
Installing package3...
Successfully installed package3

#[QPython] Press enter to exit ...

显然这不是我要的!

你可能感兴趣的:(python,青少年编程,自动化,pip,list)