Its important to know if your pip and python are using the same paths. Otherwise you might install a package with pip and it will not be accessible via python.

Here is a quick example from a Centos system. However this will work from any system with python.

Lets look at the pip version. Notice it also tells you the path where pip is installed. Lets start off by running pip or pip3.

# pip -V
pip 21.1.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)

Note pip is installed into some directory inside /usr/local/lib/python3.6/ and its also python 3.6

Now lets look at the python version by running python -V

[root@client ~]# python -V
-bash: python: command not found

Opps that didn’t find python. Maybe it is accessible via python3 on this system

[root@client ~]# python3 -V
Python 3.6.8

Okay great that worked, we see python is version 3.6.8 which matches the python 3.6 version of pip. However, notice that python tells you the exact triplet version. Additionally, we need to make sure this python is tied to the same path as pip. You can open up python and run the code import sys followed by print(sys.path), or you can one-line it with python by feeding to the -c argument, which takes in code and shows you the output.

[root@client ~]# python3 -c 'import sys; print(sys.path)'
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages']

Notice here we see that this python3 binary uses packages from the same directory as pip: /usr/local/lib/python3.6/site-packages

So this tells me that both are synced. Meaning if I install a package with pip, it will show up on this python3.

Note:

  • use pip or pip3, and python or python3
  • learn pyenv and it will help make sense of python versions and why sometimes systems come with pip,python,pip3,python3. With pyenv all of your pips will always be tied to their pythons.

Leave a Reply

Your email address will not be published. Required fields are marked *