Home > Article > Backend Development > Where is the pip command executed?
The pip command can be executed on the command line or in a script. Detailed instructions: 1. Command line (CLI), enter the pip command in the Windows command prompt, PowerShell, or the terminal of Unix/Linux/macOS; 2. Script, you can call pip in your Python script. You can also install packages using the built-in functions of Python's package manager pip. Starting from pip10.0.0, it is recommended to use the "pip._internal.utils" module.
Operating system for this tutorial: Windows 10 system, Python version 3.11.4, Dell G3 computer.
The pip command can be executed in the command line (CLI) or in a script.
1. Command line (CLI): Enter the pip command in the Windows command prompt (CMD), PowerShell, or the Unix/Linux/macOS terminal (Terminal). For example, pip install requests.
2. Script: You can call pip in your Python script. For example, you can use the subprocess module to call pip. For example:
import subprocess import sys def install(package): subprocess.check_call([sys.executable, "-m", "pip", "install", package]) install('requests')
This code will execute pip install requests in your Python script.
In addition, you can also use the built-in functions of Python's package manager pip to install packages. For example:
import pip pip.main(['install', 'requests'])
Note: Starting from pip 10.0.0, it is recommended to use the pip._internal.utils.cli module instead of using pip.main() directly. For example:
from pip._internal.utils.cli import subprocess subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'requests'])
All of the above methods can execute pip instructions in your Python script.
The above is the detailed content of Where is the pip command executed?. For more information, please follow other related articles on the PHP Chinese website!