2

I am experiencing difficulty with installing Python correctly on my Mac (Fresh Install, I wiped my PC clean). I installed firstly

  1. Home Brew
  2. Xcode through App Store
  3. Command line tools using command: "xcode-select --install"

On typing the following command: which python3

Output is as follows:

gaurangsmacbookpro@Gaurangs-New-MacBook-Pro ~ % which python

/usr/bin/python

gaurangsmacbookpro@Gaurangs-New-MacBook-Pro ~ % which python3

/usr/bin/python3

upon running the following command which I was following off a blog from this site: https://www.pyimagesearch.com/2016/12/05/macos-install-opencv-3-and-python-3-5/

brew install eigen tbb

Home brew installed python 3.9 dependencies so no when I type the following commands:

brew list python3

I get the following output:

gaurangsmacbookpro@Gaurangs-New-MacBook-Pro ~ % brew list python3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/2to3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/2to3-3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/easy_install-3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/idle3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/idle3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/pip3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/pip3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/pydoc3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/pydoc3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/python3
/usr/local/Cellar/python@3.9/3.9.1_8/bin/python3-config
/usr/local/Cellar/python@3.9/3.9.1_8/bin/python3.9
/usr/local/Cellar/python@3.9/3.9.1_8/bin/python3.9-config
/usr/local/Cellar/python@3.9/3.9.1_8/bin/wheel3
/usr/local/Cellar/python@3.9/3.9.1_8/Frameworks/Python.framework/ (3019 files)
/usr/local/Cellar/python@3.9/3.9.1_8/IDLE 3.app/Contents/ (8 files)
/usr/local/Cellar/python@3.9/3.9.1_8/lib/pkgconfig/ (4 files)
/usr/local/Cellar/python@3.9/3.9.1_8/libexec/bin/ (7 files)
/usr/local/Cellar/python@3.9/3.9.1_8/libexec/pip/ (480 files)
/usr/local/Cellar/python@3.9/3.9.1_8/libexec/setuptools/ (334 files)
/usr/local/Cellar/python@3.9/3.9.1_8/libexec/wheel/ (44 files)
/usr/local/Cellar/python@3.9/3.9.1_8/Python Launcher 3.app/Contents/ (16 files)
/usr/local/Cellar/python@3.9/3.9.1_8/share/man/ (2 files)

The contents of my ~./bash_profile file are as follows:

# Add Homebrew's executable directory to the front of the PATH

export PATH=/usr/local/bin:$PATH

export PATH="/usr/local/sbin:$PATH"

export PATH="/usr/local/opt/python@3.8/bin:$PATH"

What am I doing wrong? I just want a fresh clean install of Python 3.8 not 3.9 as there is no support for TF Lite on 3.9 yet. Can someone help me fix this mess? I will be very grateful!

Jenia
  • 374
  • 1
  • 4
  • 15
TheAnalyst
  • 21
  • 1
  • 5
  • I don't think that 3.9 has any breaking changes, does the code actually fail to run? 3.9 is the current stable, for about 6 months now. – Jared Smith Feb 06 '21 at 12:05
  • 1
    When I last tried, the GitHub repo wouldn't compile using 'CMAKE' with a python3.9 install. The website for TF Lite also recommends python 3.8.x – TheAnalyst Feb 06 '21 at 12:07
  • [Also relevant](https://apple.stackexchange.com/questions/237430/how-to-install-specific-version-of-python-on-os-x) – Jared Smith Feb 06 '21 at 12:11
  • Does this answer your question? [How can I install a previous version of Python 3 in macOS using homebrew?](https://stackoverflow.com/questions/51125013/how-can-i-install-a-previous-version-of-python-3-in-macos-using-homebrew) – Jared Smith Feb 06 '21 at 12:11
  • Thanks Jared, I will try it, but please leave open for now. This is a genuine problem as I think the new Command line tools for Xcode ships with a python3.8.2, this madness must be contained as it is messing things up. – TheAnalyst Feb 06 '21 at 12:17
  • "this madness must be contained" this is just programming. All of us deal with versioning and dependency issues every day all day unless we all make everything backwards-compatible forever. That world might be a *better* one, but it comes with it's own set of tradeoffs (cruft). In this sad broken world we inhabit, we have tools to mitigate this (containers, version managers, virtual machines, etc). Use the tools. You are not going to be able to get your Mac exactly the way you want, because tomorrow you'll need to do something that needs Python 3.9 and your careful custom setup crumbles. – Jared Smith Feb 06 '21 at 13:10
  • 1
    I appreciate what you are saying mate, but yeah when you ship something with a certain version i.e. command line tools with python@3.8.2 then you better be sure that it is what the world really wants aye, that's all I am saying. However the link you posted semi-helped. But I am starting again. I removed all my dependencies from brew and giving it another go! Thanks anyway! – TheAnalyst Feb 06 '21 at 13:14
  • 1
    I Solved this by taking a full backup of my work files and starting over on the mac. Seems to be working fine now. Certainly a last resort method. – TheAnalyst Mar 23 '21 at 05:34

1 Answers1

0

I'm a bit late at the game, but I hope this will be useful to somebody. The best solution here is to use a virtual environment, but for the sake of argument and because it is a little bit more involved, I won't discuss that as an option here and will assume you just want a specific version installed on your machine where you can just add all the dependencies you need.

From looking at the page OP was using, the easiest solution here is probably to use a distribution like Anaconda if you are particularly interested in OpenCV or that type of libraries. Then it's just a case of setting up your path like export PATH=$HOME/anaconda/bin:$PATH or whatever path you used to install Anaconda with your shell of choice.

But let's imagine that Anaconda doesn't help you and you still need a specific version of Python, and you figure 3.8.2 is good enough for your needs and a newer version wouldn't work. Using the Python version that comes with the Xcode command line tools is probably a bad idea, just like using the system installed Python is. That version is really meant to support the Apple toolchain and while I've never run into any issues with it, I would not recommend it.

Next option is is to use homebrew. Great option since most people will already be using it, and you might already have python installed as part of a dependency but maybe like OP it's not the version you were hoping for. You can still make it work by installing an older version like so brew install python@3.8 however, it comes with a few caveats. Whenever one of the python dependencies is updated, you might need to unlink and relink it so that you can continue to use the correct version. Believe me, it's no way to live.

What I've found works (in combination with virtual environments is to use pyenv. Install it through homebrew, set your shell as described in the install doc and use it to install the python version you want (very easy) and then set the global interpreter to be whatever version you want and your system will stick to it until you set it to something else. It also works great in combination with tools like pipenv which allow you to manage virtual environments.

wombat
  • 614
  • 3
  • 18