4

I have an issue, when using Visual Studio Code, and when I'm choosing the interpreter of Python to use within a code, I realize there are two different installations or Python 3, besides the two Python2 installations.

  • Python 3.7.3 on /usr/bin/python3
  • Python 3.8.2 on /usr/local/bin/python3
  • Python 2.7.16 on /usr/bin/python (I guess this is the Apple version)
  • Python 2.7.17 on /usr/local/bin/python

The problem comes when I'm trying to use the 'Extract Method' on the 3.8.2 and it tells me to update pip. How do I choose the installation to update pip?

When I run "sudo pip install --upgrade pip" it only goes to the python 2 apple version. But I can't update the pip on the other installations.

Thanks in advance.

Ivan Parra
  • 492
  • 6
  • 16

3 Answers3

1

You can run python -m pip to run pip with a particular Python version. So

sudo /usr/[local/]bin/python[3] -m pip install --upgrade pip

Square brackets [] mean optional parts.

hedy
  • 1,160
  • 5
  • 23
phd
  • 82,685
  • 13
  • 120
  • 165
  • Thank you so much! There is a correction to your answer. I ran sudo /usr/local/bin/python3 -m pip --upgrade pip but it gave me error, so I realized it was a "install" missing. sudo /usr/[local/]bin/python[3] -m pip install --upgrade pip – Ivan Parra Apr 26 '20 at 00:18
  • @IvanParra Fixed. Sorry. – phd Apr 26 '20 at 00:19
  • No need to sorry, Thanks to you I can upgrade it. I'm new to this commands. I have another question. Why do I have two different python 2 and python 3 installations? Can I remove the additional ones? O there is no problem having it? – Ivan Parra Apr 26 '20 at 00:24
  • There is no problem in having many. On Linux I have all from 2.7 to 3.8. On Windows doubly so — 32- and 64-bit. I use them to run tests for my libraries on all supported versions. – phd Apr 26 '20 at 01:27
1
  1. First new version of MacOs are built in python2 and python3 in usr/bin

  2. just leave them and install newest python

  3. then edit path which in /etc/paths put 'usr/local/bin' on the first line

  4. enjoy! now all your python3 is run in usr/local/bin which is newest and installed by yourself. Also pip is work too. if you wanna upgrade your python just run brew upgrade. It's best way to use python on mac and DONT DELETE default python2 and 3 just leave them

Runze Wang
  • 11
  • 1
0

As said in Upgrading pip for different versions of python, you can:

Use the python 3.8 interpreter to run the command:

python3.8 -m pip install --upgrade pip

Or use the pip3.8 binary directly:

pip3.8 install --upgrade pip

Note that if the Python command is not in your PATH, you must provide the full path when running the upgrade:

/usr/local/bin/python3 install --upgrade pip 
hedy
  • 1,160
  • 5
  • 23
  • Hedy, I have another question. The Mac version of python can be upgraded? Or it's better not to touch it? – Ivan Parra Apr 26 '20 at 00:35
  • @IvanParra it depends on which versions of python you need to use. If you need both python2 and also python3, I would suggest to keep one of each. So eg: `2.7.17`, and `3.8.2`. – hedy Apr 27 '20 at 01:22