Linux command
pip 命令
网络
复制后可按需替换文件名、目录或参数。
常用示例
Install a package
pip install [package]
Install a specific version
pip install [package]==[1.0.0]
Install packages from requirements file
pip install -r [requirements.txt]
Upgrade a package
pip install --upgrade [package]
Uninstall a package
pip uninstall [package]
List installed packages
pip list
Show package information
pip show [package]
Generate requirements file
pip freeze > [requirements.txt]
Install for current user only
pip install --user [package]
说明
pip is the package installer for Python, used to install and manage packages from the Python Package Index (PyPI) and other repositories. It handles dependency resolution, downloading, and installation of Python packages. Packages can be installed globally (requires root), per-user with --user, or in virtual environments (recommended). Version specifiers allow precise control: == for exact, >= for minimum, ~= for compatible versions. The requirements.txt format, generated by pip freeze, records exact versions for reproducible installations. Modern Python recommends using python -m pip instead of the bare pip command to ensure the correct Python interpreter is used.
参数
- -U, --upgrade
- Upgrade packages to newest version
- --user
- Install to user directory (~/.local)
- -r, --requirement _FILE_
- Install from requirements file
- --no-deps
- Don't install dependencies
- -c, --constraint _FILE_
- Constrain package versions using the given constraint file
- --force-reinstall
- Reinstall even if up-to-date
- -I, --ignore-installed
- Ignore installed packages
- --pre
- Include pre-release versions
- -i, --index-url _URL_
- Base URL of package index
- --extra-index-url _URL_
- Additional package index URL
- -e, --editable _PATH_
- Install in editable/development mode
- --target _DIR_
- Install to specified directory
- -y, --yes
- Don't ask for confirmation
- -q, --quiet
- Minimal output
- -v, --verbose
- Verbose output
- -V, --version
- Show version
- -h, --help
- Show help
FAQ
What is the pip command used for?
pip is the package installer for Python, used to install and manage packages from the Python Package Index (PyPI) and other repositories. It handles dependency resolution, downloading, and installation of Python packages. Packages can be installed globally (requires root), per-user with --user, or in virtual environments (recommended). Version specifiers allow precise control: == for exact, >= for minimum, ~= for compatible versions. The requirements.txt format, generated by pip freeze, records exact versions for reproducible installations. Modern Python recommends using python -m pip instead of the bare pip command to ensure the correct Python interpreter is used.
How do I run a basic pip example?
Run `pip install [package]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -U, --upgrade do in pip?
Upgrade packages to newest version