0

I have both python 2.7.16 and python 3.7.3 on my Macbook air.
I don't use python 2.7.16 so I want to remove it, but I understood that this could break my Mac.
I am frustrated from using python3 and pip3 instead of python and pip is there a way to make all of the python3 commands to be accessed by using python (without 3) instead of python 2 and make python 2 be accessible by using python2?
tnx ahead

Finci
  • 108
  • 1
  • 10
  • 2
    If you work with virtual environments, you'll need python3 to create the venv, but after you have sourced it, you can just use python and pip from within it. I think this is a safer option than changing any of the defaults on your mac, and it will make your projects more reproducible. – Dan May 04 '20 at 16:29
  • 2
    You could also add `alias python=python3` to your `.zshenv` :) – grooveplex May 04 '20 at 16:36
  • The safest option is to use a virtual environment. Then you can use everything in this virtual environment and it doesn't mess up with other dependencies. Check [python virtual env](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/) –  May 04 '20 at 16:50
  • Check https://stackoverflow.com/questions/3819449/how-to-uninstall-python-2-7-on-a-mac-os-x-10-6-4 – Keldorn May 04 '20 at 17:31

1 Answers1

0
(base) shrub$ /usr/bin/py
pydoc             python            python2.7         pythonw
pydoc2.7          python-config     python2.7-config  pythonw2.7

Looking in /usr/bin there is a python executable (which when run opens a shell with python3) and a python2.7 executable (which when run opens a shell with python2).

(base) shrub$ python
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.

(base) shrub$ python2.7
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Running python scripts with python (python hello.py for example) should default to python3 and running scripts with python2.7 (python2.7 hello.py for example) will run them with python2.

Also there is a script called 2to3 which can help you with converting your python2 code to python3 :) https://docs.python.org/3.0/library/2to3.html