How do I deal with pip in different python versions?

I had python 3.8 installed and then I installed python 2.7. I am trying to run a python program with py -2 program.py in vs code using with python 2.7 as selected environment and I am getting an error, ImportError: No module named googlemaps even though I have already installed.

If I run the program using Python3 then it would run fine. Also when I open vs code using python 2.7 as selected runtime environment then I would get a warning Linter Pylint is not installed. If I click on install then I would get another warning There's no Pip installer available in the selected environment.

Also even though I have changed the python path from 3.7 to 2.7, default python version will still show up as 3.7 when I runPython in command line.

Things that I have tried to install the googlemaps module for python 2 after googling for solutions,

pip2 install googlemaps--upgrade

py -2 -m pip install googlemaps

Add Comment
2 Answer(s)

If you have your python2 binary located, you can just call it directly:

/usr/bin/python2 -m pip install googlemaps 

And if you’re not sure where your python binary is, you can use

import sys print(sys.executable) 

to locate it.

And if you don’t have pip, you should install it by downloading this file: https://bootstrap.pypa.io/get-pip.py

then running:

/usr/bin/python2 get-pip.py 
Answered on July 16, 2020.
Add Comment

It is recommended to install Python 3.8 using Pyenv and also when you are using different versions of python, it is very useful

curl https://pyenv.run | bash pyenv install 3.8.1 pyenv virtualenv 3.8.1 venv pyenv local venv 

with pyenv local you set your version for use. If after this you run

pyenv version 

It will output to 3.8.1

With regards to pip installation, run

whereis python 

and if it outputs to

usr/bin/python2 then you can use pip for installing python2 packages and pip3 for packages compatible to python3.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.