Pip doesn't work in Python - Ubuntu

To install pip in Ubuntu, a standard package manager, we can run command - for Ubuntu 16.04

sudo apt install python3-pip

To check installation version, we run respectively

pip -V

pip3 -V

and returns

pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

And it seems all done. However, this raises a problem before you really start to use the pip.

 

Key Problem

The key question here is that the pip version does not specifically locate correct python version which we desire to be python 3.6 in this case whilst now 2.7. This can be an issue for version mismatch because the latest pip version no longer served python 2.7.

Hence you will not be able to install dependencies via the pip for python development. You may receive system errors containing

    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

 

Solution

run

curl -fsSL https://bootstrap.pypa.io/pip/3.5/get-pip.py | python3.6

given your python version is 3.6

 

Check again your pip and pip3 version

pip3.6 -V

and

pip3 -V

and you expect to see

pip 20.3.4 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

which indicates pip is now successfully locating python 3.6.


【Further discussion】

https://stackoverflow.com/questions/66212924/pip-sys-stderr-writeferror-exc-with-python-3-5

https://stackoverflow.com/questions/65869296/installing-pip-is-not-working-in-python-3-6


 

留言

這個網誌中的熱門文章

Create NFT on Solana (Windows)

Obtain IP address (Windows / Linux sys.) from Python – plus simple practice