[Python] Let's remember the new writing style after pip10

If you use the pip command as it is like pip list, the following warning will be displayed and you will be surprised. This way of writing seems to be old.

WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.

Not recommended to use single pip

It is recommended to use the pip that comes with Python as follows.

$ python3 -m pip [pip command]

Using the pip that comes with Python doesn't change anything, but I'll post a snippet of my favorite pip command.

To list installed packages with pip

$ python3 -m pip list

When installing packages with pip

$ python3 -m pip install [package name]

When installing by specifying the version with pip

$ python3 -m pip install [package name]==Specified version

Example) When installing opencv-python with version 3.4

$ python3 -m pip install opencv-python==3.4

However, there is no version called 3.4, so it will tell you which version you can specify carefully.

ERROR: Could not find a version that satisfies the requirement 
opencv-python==3.4.10.35 (from versions: 
3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 
3.4.0.12, 3.4.0.13, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 
3.4.3.18, 3.4.4.19, 3.4.6.27, 3.4.7.28, 4.0.1.24, 4.1.0.25, 4.1.1.26)

ERROR: No matching distribution found for opencv-python==3.4

I am very grateful.

If you want to downgrade a version of an already installed package

$ python3 -m pip install [package name]==Specified version

Just like a new installation, you can just run install.

Installing collected packages: opencv-python
  Attempting uninstall: opencv-python
    Found existing installation: opencv-python 4.1.1.26
    Uninstalling opencv-python-4.1.1.26:
      Successfully uninstalled opencv-python-4.1.1.26
Successfully installed opencv-python-3.4.7.28

Those installed in this way will be automatically uninstalled.

Finally

Basically, there is no problem if you remember "** $ python3 -m pip **". Note that Python comes with pip since version 3.4.

Related article

-[Python] Enable pip on macOS

environment

Recommended Posts

[Python] Let's remember the new writing style after pip10
[Blender x Python] Let's master the material !!
Let's read the RINEX file with Python ①
Let's summarize the Python coding standard PEP8 (1)
Let's observe the Python Logging cookbook SocketHandler
From Python 3.4, pip becomes the standard installer! ??
Introduction to Python Let's prepare the development environment
Let's parse the git commit log in Python!
[Python] Let's execute the module regularly using schedule
Python> 3.14_1592_6535_8972> PEP515 (Python v3.6 or later possible writing style)
Calculation result after the decimal point in Python
The 18th offline real-time writing problem in Python
I touched some of the new features of Python 3.8 ①
A note about the new style base class
The 19th offline real-time writing problem in Python