Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS: Multiple python versions installed and unmanageable. Cleanup wanted

I've been on macOS for 2 years now and in the past year I've begun to work a lot in Python via VScode. But lately I have been running into so many problems because I didn't set up python properly from the start. I have multiple versions and modules installed globally (I know that is bad)... But I was wondering if anyone had advice about how I can clean up the Python set up so that there is the latest version being used and all modules will be installed properly.

I used homebrew as well and that is just adding to the mess. I want to do this right so that I can stop messing with configurations every day and just be able to develop.

I'll include some basic terminal outputs but if there is more that anyone would like to see I would be happy to provide more detail. If starting from scratch is the best thing to do then I'll do it. I don't know my way around all the configuration files and pathing so I'll need some help if that is what I'll have to do.

$ which python
/usr/bin/python

$ which python3
/usr/local/bin/python3

$ python --version
Python 2.7.16

$ python3 --version
Python 3.7.7

$ python3
Python 3.7.7 (default, Mar 10 2020, 15:43:33) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__file__
'/usr/local/lib/python3.7/site-packages/tensorflow/__init__.py'

VScode has the following interpreters available (not sure if that helps)

  • 2.7.16 /usr/bin/python
  • 2.7.16 /System/Library/Frameworks....
  • 3.7.3 /usr/bin/python3
  • 3.7.7 /usr/local/bin/python3
  • 3.7.7 /usr/local/opt/python/bin/python3.7

Any help would be awesome!! I'm just tired of fighting with this and wanted to ask for help

like image 792
micshapicsha Avatar asked Nov 30 '25 03:11

micshapicsha


1 Answers

Having multiple versions of python is not really a propblem per se.

What I recommend is :

# In $HOME/.bashrc or .zshrc
PATH=/usr/local/bin:$PATH
cd /usr/local/bin
ln -fs python3 python
# Once the first and this step done, when you type [python],
# you'll be using /usr/local/bin/python3

As the first line of your python scripts, put :

#!/usr/bin/env python

This way, you ensure your are always using the version /usr/local/bin/python3

like image 92
Philippe Avatar answered Dec 02 '25 17:12

Philippe