Send by LINE
B! Bookmarks in Hate-bu
Bookmarks in Pocket
RSS feeds

Python pip, How to use package management

python image

Python's pip is a command for managing packages.

Packages are multi-functional extensions available in python, and you can install the required features in a package to implement your program efficiently.

Here is an easy-to-understand explanation of how to use the pip command.

This is written by a Japanese who can't speak English with the help of translation application. Sorry if it's not good.

What is a Python package?

Python has many features that can be added. These features are available as packages on GitHub and other sites. The tool to manage these packages is pip.

You can think of it as being similar to composer in php or gem in Ruby.

LanguagePackage Management

The pip command is used to add, update, and remove packages. Also, frameworks such as Django can be easily installed using this pip.

In Python, you should always assume that pip is used.

Difference between pip and pip3

The major update from Python 2.x series to 3.x series has changed a lot.

The v2 and v3 are no longer compatible, and it is difficult to migrate to v3. v2 programs may not work on v3. So we have to make sure that v2 and v3 coexist.

The pip command is also separated.


The functions of pip and pip3 commands are the same, only the target version is different.

When you are using only v3, you can use both pip and pip3 and the behavior is the same.

The pip command is installed by default in Python since v2.7, so there is no need to install it.

In this article, I will introduce you to five commands that are the minimum required to install the package.

How to install the package

Package installation commands
python -m pip install 'package_name'

To install the package, use the install command.

The pip command is located in the Scripts directory of your python installation. This directory is usually set in the PATH, and "python -m" can be omitted.

On Windows, the PTAH setting for Scripts is also set during installation.

How to update the package

Update command
python -m pip install -U 'package_name'

To update the package, use the install command. If you specify the -U (--upgrade) option, it will be an update.

How to uninstall the package

Uninstall command
python -m pip uninstall 'package_name'

To uninstall the package, use the uninstall command.

The install / uninstall command is "install" / "uninstall , so it's easy to remember.

How to display the package list

List display command
python -m pip list

Displays the list of installed packages.

How to check for package updates

Package update confirmation command
python -m pip list -o

Check if there is a version of the package to be updated.

Subcommands of pip

There are also many other commands available. Here are some of the most commonly used ones.

install - Install / Update

install command
python -m pip install 'package_name'

Install / Upgrade the package.


-U, --upgrade: Update
Package upgrade command
python -m pip install -U 'package_name'

Upgrade the package.

Upgrading the pip command
python -m pip install --upgrade pip

Upgrade the pip command itself.

-r : Import installation
Bulk install command
python -m pip install -r import.txt

Install from the package list file (import.txt) created by the freeze command.

It is used to install packages together. It is also used to migrate the python environment.

uninstall : Uninstall

Uninstall command
python -m pip uninstall 'package_name'

Uninstall the package.

list : List display

List display command
python -m pip list

Displays the list of installed packages.


-o : Update confirmed
Update information display
python -m pip list -o

Displays the packages that can be updated.

-u : display latest version package
Latest version display
python -m pip list -u

Displays the packages that contain the latest version.

-e : Development mode package display
Display the list of development mode packages
python -m pip list -e

Displays the packages installed with "install -e".

The packages put in by "install -e" will be installed by setuptools. It is used for packages under development, so it is not used in the production environment.

--pre : Beta version display
List view of beta versions
python -m pip list --pre

It also shows the beta version.

It is not stable, but it has a lot of challenges such as the latest features.

freeze : Export the package list

Exporting the package list
python -m pip freeze > export.txt

Outputs the list of currently installed packages to a file.

The output files can be installed together with "pip install -r".

show : Display detailed package information

Display detailed package information
python -m pip show 'package_name'

Displays detailed information about the package.

check : Package dependency check

Dependency check
python -m pip check

Check for package dependencies.

Some packages do not work by themselves and require other packages.

Package A needs package B

It goes on to say

Package A depends on package B

help : Display help

help display
python -m pip help

Displays help for the pip command.

-V : Version check

View the version of the pip command
python -m pip -V

Displays the version of the pip command.

Leave a Reply