+1 vote
in Programming Languages by (11.9k points)

I upgraded Ubuntu from 18 to 20. Now I am facing an issue with "pip". When I use "pip" to install any Python package, I get the following warning message:

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.

1 Answer

0 votes
by (21.4k points)
edited by

Since you upgraded Ubuntu from 18 to 20, your system should have the latest Python. Ubuntu 18 has Python 3.6 whereas Ubuntu 20 has Python 3.8.

From the warning message, it is clear that the issue is with the wrapper, not with the "pip" command. When you run "pip", it runs the latest pip that came with Python3.8 using the old wrapper from Python3.6.

To fix the warning message, you can do one of the followings:

1. Instead of running "pip install", you can run the following command to install any Python package.

python3 -m pip install <package name>

On Ubuntu, "python" is for Python2, so use "python3".

OR

2. You need to perform the following steps to fix the warning message.

  • Get the location of the new "pip" package using the following command:

pip -V

It should give the following line in the output: "pip 20.0.2 from /home/username/.local/lib/python3.8/site-packages/pip (python 3.8)"

  • cd to the above folder "/home/username/.local/lib/python3.8/site-packages/pip" and then type ls to see the list of files and directories. It should show the followings:

__init__.py  _internal  __main__.py  __pycache__  _vendor

  • View the file "__main__.py": cat __main__.py
  • The file should have the following line. This is the new wrapper that you need to use for pip.

from pip._internal.cli.main import main as _main  # isort:skip # noqa

  •  Run command type -a pip. It will show the location of the pip command. The output should look like the following.

pip is /usr/local/bin/pip

  •  Edit the file for pip command: sudo nano /usr/local/bin/pip . Replace the old wrapper with the new wrapper as follows:

#from pip._internal.main import main
from pip._internal.cli.main import main #as _main

  • Save the file and exit. Now run "pip install" and you will not see the warning message.
...