Python throws error “pip is being invoked by an old script wrapper” either due to incompatible pip version or due to multiple versions of pip.
Solution
To resolve this error, you can follow these steps –
- Try upgrading your pip version. If required, use force upgrade.
- Uninstall pip and reinstall it.
- Check if you have multiple versions of pip. If yes, then keep the system pip only.
- If pip path is not added in system environment, then do add it.
- Locate the boot file (
/usr/bin/pip
) and check if it is still old after your pip upgrade.
Upgrading pip version
Try force upgrading the pip version using this command –
python3 -m pip install --upgrade --force-reinstall pip
Multiple pip versions
If this issue appeared after your installation of pip, then probably you had pip already installed in your system. Try removing newly installed version using this command –
python -m pip uninstall pip
Now you will have the system pip only.
Pip Paths Mismatch
Note the path when you upgraded pip. Now, run which pip
and check the path. If both paths are not same, it means you are not using the upgraded pip. You may uninstall the pip from the path returned by which pip
command.
Old Boot File
Open the boot file located at /usr/bin/pip
and check the code. If the code is like this –
#!/usr/bin/python3 # GENERATED BY DEBIAN import sys # Run the main entry point, similarly to how setuptools does it, but because # we didn't install the actual entry point from setup.py, don't use the # pkg_resources API. from pip import main if __name__ == '__main__': sys.exit(main())
or the shebang is pointing to python2 (#!/usr/bin/python2
) then you need to update this file with this code –
#!/usr/bin/python3 # -*- coding: utf-8 -*- import re import sys from pip._internal.cli.main import main if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) sys.exit(main())
One of these steps will solve the error.
Conclusion
In this article we saw different ways to resolve pip is being invoked by an old script wrapper Python error. The most common reasons are multiple pip installations and using the wrong version. Check for the pip boot file code if it is old.