Installing Python3 on MacOS using Homebrew has error "Failed to import the site module"

6

1

So I'm trying to reinstall python3 using Homebrew on Mac OSX El Capitan Version 10.11.6, but I keep getting errors. The commands I'm using to install python3 are the following:

$ brew install python3

The first command seems to work fine, no errors are thrown.

$ brew linkapps

This second command throws the following errors:

Warning: `brew linkapps` has been deprecated and will eventually be removed!

Unfortunately `brew linkapps` cannot behave nicely with e.g. Spotlight using
either aliases or symlinks and Homebrew formulae do not build "proper" `.app`
bundles that can be relocated. Instead, please consider using `brew cask` and
migrate formulae using `.app`s to casks.
Linking: /usr/local/opt/python/IDLE.app
Linking: /usr/local/opt/python/Python Launcher.app
Linking: /usr/local/opt/python3/IDLE 3.app
Linking: /usr/local/opt/python3/Python Launcher 3.app
Linking: /usr/local/opt/qt5/libexec/Assistant-qt5.app
Linking: /usr/local/opt/qt5/libexec/Designer-qt5.app
Linking: /usr/local/opt/qt5/libexec/Linguist-qt5.app
Linking: /usr/local/opt/qt5/libexec/pixeltool-qt5.app
Linking: /usr/local/opt/qt5/libexec/qdbusviewer-qt5.app
Linking: /usr/local/opt/qt5/libexec/qml-qt5.app
Linked 10 apps to /Applications

When I try to run $ python3 in terminal, I get the following error:

Failed to import the site module
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/site.py", line 73, in <module>
    __boot()
  File "/usr/local/lib/python2.7/site-packages/site.py", line 26, in __boot
    import imp  # Avoid import loop in Python >= 3.3
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/imp.py", line 27, in <module>
    import tokenize
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tokenize.py", line 33, in <module>
    import re
  File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 142, in <module>
    class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'

Would love some advice on how to solve this. The goal is that I can install python3 and opencv3 as suggested in this tutorial however I am stuck with python3 not working.

stwhite

Posted 2017-04-05T01:37:45.220

Reputation: 160

Answers

16

I solved this thanks to https://stackoverflow.com/a/42214539/5511915, with a simple unset PYTHONPATH (which was set to PYTHONPATH=/usr/local/lib/python2.7/site-packages, conflicting with python3)

Pierre B

Posted 2017-04-05T01:37:45.220

Reputation: 161