73

I'm trying to install tensorflow onto a Mac with Python3.7. However, I'm getting the error:

$ pip3 -v install tensorflow
...    
    Skipping link https://files.pythonhosted.org/packages/56/7a/c6bca0fe52a94ca508731d8b139e7dbd5a36cddc64c19f422f97e5a853e8/tensorflow-1.10.0rc1-cp36-cp36m-win_amd64.whl#sha256=3ab24374888d6a13d55ce2e3cf4ba0c9cd6f824723313db5322512087525cb78 (from https://pypi.org/simple/tensorflow/); it is not compatible with this Python
  Could not find a version that satisfies the requirement tensorflow (from versions: )
Cleaning up...
Removed build tracker '/private/var/folders/4n/9342s4wd3jv0qzwjz8rxrygr0000gp/T/pip-req-tracker-3p60r2lo'

No matching distribution found for tensorflow

From what I can gather this is happening because tensorflow doesn't yet support Python3.7. As a workaround I want to install Python3.6 alongside 3.7 and then install tensorflow to that version. However, I'm new to Mac and not sure of the correct way to do this without potentially messing with the preexisting Python version.

I've tried using brew, but it looks like Python3 is as specific as it gets. What is the correct way to do what I'm after?

Sam
  • 1,893
  • 2
  • 21
  • 37

3 Answers3

154

Try using brew for example if already using Python 3:

$ brew unlink python

Then install python 3.6.5:

$ brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

To get back to python 3.7.4_1 use:

$ brew switch python 3.7.4_1

And if need 3.6 again switch with:

$ brew switch python 3.6.5_1
wonton
  • 5,487
  • 4
  • 39
  • 73
nbari
  • 20,729
  • 5
  • 51
  • 86
  • I get the error `Error: No such keg: /usr/local/Cellar/python` – Sebastian Feb 10 '19 at 22:59
  • 10
    I added --ignore-dependecies to make it work (recursive dependency error with sphinx-doc): brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb – Vincent J Feb 11 '19 at 11:12
  • 3
    Is available a brew Formula link for Python 3.6.7? Python 3.6.5 has some severe issues - https://bugs.python.org/issue24658 and its install should be avoided! – loretoparisi Feb 14 '19 at 18:51
  • I had this problem as well `Error: No such keg: /usr/local/Cellar/python` . It solved by installing python, the latest version, using brew, then unlink it and so on. So first install the latest version using brew. – Shahin Jul 16 '19 at 18:31
  • For some reason switching between python versions doesn't work for me. Instead, whereever I would use `python`, I use `python3.6` instead, and when installing packages with pip, I use `python3.6 -m pip install package_name` – stevec Aug 05 '19 at 00:49
  • For some reason, my network using python3.6 wasn't work on macOS Catalina with zsh, so I ran: `$ brew doctor && brew missing` it shows me that openssl lib for some reason not installed and then install it using: `$ brew install openssl`. – Alexandr S. Oct 26 '19 at 15:43
  • Is there a quick way to see which versions are installed? (i.e. which options can be switched to) – stevec Jul 10 '20 at 11:59
39

If you are using mac, you can install pyenv from Brew, install the desired versions, list the installed versions, and activate each version locally or globally.

brew install pyenv
pyenv install 3.6.9
pyenv install 3.7.4    
pyenv versions
pyenv global 3.7.4 3.6.9
$ python3.6 --version 
Python 3.6.9 

$ python3.7 --version
Python 3.7.4

PS: Global activation worked only after restarting the computer. You need to prepend $(pyenv root)/shims to the left of your PATH environment variable.

charlesreid1
  • 3,218
  • 2
  • 26
  • 43
Luís De Marchi
  • 935
  • 12
  • 23
  • I haven't used `pyenv` before. What do I do after the last command? `python36 myscript.py` and `python3.7 myscript.py` both fail. – falsePockets Dec 24 '19 at 03:55
  • 1
    Add, the answer is to prepend `$(pyenv root)/shims` to the `PATH`. I'll update the answer to say so. – falsePockets Dec 24 '19 at 04:03
  • It is necessary to add export `export PATH=$(pyenv root)/shims:PATH` to the `.bash_profile` – Saravanakumar G Nov 24 '20 at 00:17
  • 1
    doing what @SaravanakumarG is suggesting completely broke my terminal, I couldn't use a single command anymore. The right way is `export PATH="$(pyenv root)/shims:$PATH"` – Raphael Royer-Rivard Jan 12 '21 at 23:00
  • If you mistakenly messed up your PATH by following what @SaravanakumarG is suggesting, just run PATH=/bin:/usr/bin in your terminal, fix the export statement and then source the file again source ~/.bash_profile – Ahmed Kamal Feb 02 '21 at 14:43
  • Having issues with `pyenv install 3.6.9` on M1 mac – Omar Shabab Mar 06 '21 at 14:01
9

When you mess around with system python versions, I strongly recommend using pyenv - it makes life so much easier. You would simply run

brew install pyenv
pyenv install 3.6.5
pyenv install 3.7.4

Then you can run pyenv local [python version]

wonton
  • 5,487
  • 4
  • 39
  • 73