Answer the question
In order to leave comments, you need to log in
How to work with cmd through code in a file in Python?
the simplest example, installing an update for a specific pip package in cmd looks like this:
pip install <...> --upgrade
the question is: how, using a python file (script), to automate module updates, without manual input on the command line?
Roughly speaking, as I imagine it, in the .py file I have to write the command that I want to pass to cmd. I just don't know how.
The question seems simple to me, I'm just a beginner
Answer the question
In order to leave comments, you need to log in
There is already a ready-made pipenv, poetry or maybe some other similar ones. Well, read the doc about pip, it's possible to work with it from python
subprocess module.
subprocess.run to run a command with execution pending.
subprocess.Popen to run the command in a separate process (will not interrupt the execution of the main script).
Example
import subprocess
module = "lxml"
subprocess.run(["pip", "install", module, "--upgrade"])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question