Original title Use python to write code: pip list, list: pip install library 1 library 2 library 3..., to facilitate one-time installation errors
Completely solve the problem of pip installation library
Write code in python: pip list List: pip install library 1 library 2 library 3 this output
The following is an example of using Python to write code to achieve output similar to pip list
and pip install package1 package2 package3
:
import pkg_resources # List installed packages and versions installed_packages = [p for p in pkg_resources.working_set] for package in installed_packages: print(f"{<!-- -->package.project_name} ({<!-- -->package.version})") #Install the specified package 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}...") # Execute the installation command, this is just a simulation output print(f"Successfully installed {<!-- -->package}")
In the above code, we use the pkg_resources
module to get the list of installed packages and display their names and versions. We then loop through the list of packages to install and check if each package is already installed. If it has been installed, the corresponding information is displayed; otherwise, the simulation result of the installation command is output.
Please note that this is just a simple demonstration code, and the actual execution of the installation command requires the use of appropriate methods, such as using the subprocess
module to execute the command line installation command.
/data/user/0/org.qpython.qpy/files/bin/qpy thon3.sh "/storage/emulated/0/qpython/datapoint1.1.1.py" & amp; & amp; exit python/datapoint1.1.1.py" & amp; & amp; 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) params (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) prolog (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 ...
Ignore the second method
import subprocess import re # Execute the pip list command and get the output results output = subprocess.check_output("pip list", shell=True).decode() # Use regular expressions to match a list of library names pattern = re.compile(r'^\S + ') library_names = pattern.findall(output, re.MULTILINE)[2:] # The list of spliced library names is pip install command install_command = "pip install " + " ".join(library_names) print(install_command)
This includes a message: “A new release of pip available”. This appearsto be generated by the pip
command during execution.
According to this prompt message, you can try upgrading pip
first, and then get a list of library names.
?Enlarge move?
Query pip installed libraries
pip list
Save version of installed library list
pip list > /storage/emulated/0/datacenter/pipinstallation/pip_list.txt
Save the installed library address and remove the library version
xargs -n 1 pip install < /storage/emulated/0/datacenter/pipinstall/pip_list.txt
Direct installation
pip list | awk '!/^\-/{print $1}' > /storage/emulated/0/datacenter/pip installation/pip_list.txt