1

On Mac OS.

Downloaded the Python from their website.

Python -V return Python 2.7.16, and python3 -V return Python 3.9.4

Installed pip with : python3 get-pip.py, got Successfully installed pip-21.0.1

But when I run pip -V I get File "/usr/local/bin/pip", line 1.... SyntaxError: invalid syntax

After reading here a lot, i could not understand (in simple words for dumbs) :

  1. How could you "alias" or update python to show/run in version 3+ ?
  2. Why I can't get the pip version if it's installed ?
Shulas
  • 91
  • 1
  • 7
  • Try pip --version – Buddy Bob Apr 19 '21 at 19:05
  • 1
    You might need to use `pip3` given that you have two different python versions. – astrochun Apr 19 '21 at 19:07
  • --version Same exact error. syntax error that show many paths to files, something like : Traceback (most recent call last): File "/usr/local/bin/pip", line 11, in load_entry_point('pip==21.0.1', 'console_scripts', 'pip')() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point – Shulas Apr 19 '21 at 19:07
  • @astrochun that's strange because i just downloaded both - the most updated versions. Mac use python 2 and i understand you cant touch it. – Shulas Apr 19 '21 at 19:10

2 Answers2

1

Use pip as a module instead

% python3 -m pip --version
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
ti7
  • 16,375
  • 6
  • 40
  • 68
  • thank you, this return "pip 21.0.1 from /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip (python 3.9)" , can you explain in simple words what does it means and what did we do ? – Shulas Apr 19 '21 at 19:12
  • anytime ; this is probably a better explanation than I can give here https://stackoverflow.com/questions/25749621/whats-the-difference-between-pip-install-and-python-m-pip-install – ti7 Apr 19 '21 at 19:22
  • thank you, but your answer was not installing anything? and i installed pip with python3 get-pip.py, which is non of the options in the question you linked? very confused. – Shulas Apr 19 '21 at 19:30
  • investigating a little, it comes from [homebrew](https://brew.sh/)'s Python package which bundles it `brew ls --verbose python@3.9 | grep -i pip` ; it can be installed as `brew install python@3.9` – ti7 Apr 19 '21 at 19:42
0

Anyone who's interested , what i had to do is to

  1. CD the project on terminal
  2. run python3 -m venv env (this create virtual environment of python3 inside project)
  3. run source env/bin/activate activate it.
  4. now pip --version or python --version will return the right results.

From my basic knowledge i understand that the mac is using python2 which we don't want to interrupt, so we install python3 and create a 'virtual environment' for it inside our project folder, once its in, we can install all other things.

to deactivate (stop the virtual env) we run deactivate

Shulas
  • 91
  • 1
  • 7