Recently upgraded to MacOS Catalina and zsh shell. Since the upgrade it seems we have Python 3 and no longer 2.x so to work with older Trellis setups using Python 2.7 you need a fix

Bad Interpreter Error

Error we got using Ansible was a bad interpreter error. Python 2.7 is not to be found:

zsh: /usr/local/bin/ansible-vault: bad interpreter: /usr/local/opt/python@2/bin/python2.7: no such file or directory

And that was correct because when we checked /usr/local/opt we only had Python 3.

Brew Installation Python 2

So we did a

brew install python@2

to install Python 2 as an option besides the natively installed Python 3. This took quite some time as we had not updated Brew in a long time and as compilation was done from source

➜  trellis git:(master) brew install python@2
 Updating Homebrew…
 ==> Auto-updated Homebrew!
 Updated 4 taps (heroku/brew, homebrew/core, homebrew/cask and homebrew/services).
 ==> New Formulae
 adios2                     git-delta                  mpv                        pnpm
 alp                        gleam                      mysql-connector-c++@1.1    prestosql
 appium                     gmt@5                      navi                       pylint
 arduino-cli                govc                       nbdime                     tdkjs
 atasm                      grin                       ngt                        tektoncd-cli
 awsume                     grin-wallet                node@12                    toast
 bingrep                    helm@2                     notifiers                  trader
 calceph                    javacc                     numpy@1.16                 ttyplot
 cf-tool                    jd                         oauth2l                    tweak
 comby                      kyma-cli                   onefetch                   virustotal-cli
 cups                       libtensorflow@1            openjdk                    wagyu
 dafny                      manticoresearch            openjdk@11                 wal2json
 diffr                      minikube                   openjdk@12                 xgboost
 dvc                        mpi4py                     pnetcdf
 ==> Updated Formulae
 aspell ✔                            gitless                             pdf2htmlex
 cmake ✔                             gitmoji                             pdf2json
 curl ✔                              gitup                               pdfcpu
 curl-openssl ✔                      gitversion                          pdftk-java
 git ✔                               gjs                                 pdftoipe
 glib ✔                              glade                               percona-server
 gnutls ✔                            glances                             percona-xtrabackup
 heroku/brew/heroku ✔                glib-networking                     perltidy
 heroku/brew/heroku-node ✔           glooctl                             petsc
 iproute2mac ✔                       gmic                                petsc-complex
 kubernetes-cli ✔                    gmime                               pgbadger
 libtiff ✔                           gmt                                 pgcli
 libxml2 ✔                           gnome-builder                       pgformatter
 mariadb ✔                           gnome-latex                         pgrouting
 node ✔                              gnome-recipes                       pgweb
 node@10 ✔                           gnumeric                            phoronix-test-suite
 p11-kit ✔                           gnunet                              php-code-sniffer
 php ✔                               gnuradio                            php-cs-fixer
 python ✔                            go                                  php@7.1
 redis ✔                             go-bindata                          php@7.2
 sqlite ✔                            go@1.12                             phpmyadmin
 terraform ✔                         gobby                               phpstan
 tor ✔                               gocryptfs                           phpunit
 yarn ✔                              godep                               picard-tools
 abcm2ps                             goffice                             pioneer
 ........
 gifski                              osm-gps-map                         zbar
 ginac                               osmium-tool                         zint
 git-annex                           osqp                                zita-convolver
 git-archive-all                     osquery                             znc
 git-cola                            ott                                 zola
 git-quick-stats                     oxipng                              zookeeper
 git-revise                          packer                              zrepl
 git-town                            pagmo                               zsh-completions
 gitfs                               paket                               zsh-history-substring-search
 gitg                                pango                               zshdb
 gitlab-gem                          parallel                            zydis
 gitlab-runner                       pastel
 gitleaks                            pdal
 ==> Renamed Formulae
 jupyter -> jupyterlab      kubernetes-helm -> helm    presto -> prestodb         usbmuxd -> libusbmuxd
 ==> Deleted Formulae
 aiccu             dcal              gmtl              mariadb@10.0      pound             riak
 bdsup2sub         erlang@17         hana              mysql@5.5         protobuf@3.1      supersonic
 cockroach         gmt@4             llvm@4            pbrt              raine             wine
 ==> minikube has been moved to Homebrew.
 To uninstall the cask run:
   brew cask uninstall --force minikube
 ==> Installing minikube…
 ==> Installing dependencies for minikube: kubernetes-cli
 ==> Installing minikube dependency: kubernetes-cli
 ==> Downloading https://homebrew.bintray.com/bottles/kubernetes-cli-1.16.3.catalina.bottle.tar.gz
 ==> Downloading from https://akamai.bintray.com/0f/0ffd9ee9bb5026ae526a09fe50591a94a1a987f52c5866e32aefb79b
 ################################################################## 100.0%
 ==> Pouring kubernetes-cli-1.16.3.catalina.bottle.tar.gz
 ==> Caveats
 Bash completion has been installed to:
   /usr/local/etc/bash_completion.d
 zsh completions have been installed to:
   /usr/local/share/zsh/site-functions
 ==> Summary
 🍺  /usr/local/Cellar/kubernetes-cli/1.16.3: 232 files, 52.3MB
 ==> Installing minikube
 ==> Downloading https://homebrew.bintray.com/bottles/minikube-1.5.2.catalina.bottle.tar.gz
 ==> Downloading from https://akamai.bintray.com/6c/6cab6126b65a45912587339eddf252729e4ad16b4bfd327454204b46
 ################################################################## 100.0%
 ==> Pouring minikube-1.5.2.catalina.bottle.tar.gz
 ==> minikube cask is installed, skipping link.
 ==> Caveats
 Bash completion has been installed to:
   /usr/local/etc/bash_completion.d
 zsh completions have been installed to:
   /usr/local/share/zsh/site-functions
 ==> Summary
 🍺  /usr/local/Cellar/minikube/1.5.2: 8 files, 51.5MB
 ==> brew cleanup has not been run in 30 days, running now…
 Removing: /Users/jasper/Library/Caches/Homebrew/aspell--0.60.7.mojave.bottle.tar.gz… (115.6MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/curl-openssl--7.66.0.mojave.bottle.tar.gz… (1MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/glib--2.62.0_1.mojave.bottle.tar.gz… (4.5MB)
 Removing: /usr/local/Cellar/kubernetes-cli/1.10.1… (178 files, 52.8MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/php--7.3.10.mojave.bottle.tar.gz… (19.9MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/python--3.7.4_1.mojave.bottle.tar.gz… (14.6MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/python--3.7.4.mojave.bottle.tar.gz… (14.6MB)
 Removing: /Users/jasper/Library/Caches/Homebrew/sqlite--3.29.0.mojave.bottle.tar.gz… (1.9MB)
 Removing: /Users/jasper/Library/Logs/Homebrew/nghttp2… (64B)
 ......
 Removing: /Users/jasper/Library/Logs/Homebrew/openssl@1.1… (64B)
 Removing: /Users/jasper/Library/Logs/Homebrew/openldap… (64B)
 Removing: /Users/jasper/Library/Logs/Homebrew/libev… (64B)
 Pruned 17 symbolic links and 1 directories from /usr/local
 ==> Caveats
 ==> kubernetes-cli
 Bash completion has been installed to:
   /usr/local/etc/bash_completion.d
 zsh completions have been installed to:
   /usr/local/share/zsh/site-functions
 ==> minikube
 Bash completion has been installed to:
   /usr/local/etc/bash_completion.d
 zsh completions have been installed to:
   /usr/local/share/zsh/site-functions
 Linking /usr/local/Cellar/minikube/1.5.2… 3 symlinks created
 ==> Installing dependencies for python@2: sqlite
 ==> Installing python@2 dependency: sqlite
 ==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.catalina.bottle.tar.gz
 ==> Downloading from https://akamai.bintray.com/38/38c39121f7634ec563bb201b483f66cf567dfe61e02624ffb06f620f
 ################################################################## 100.0%
 ==> Pouring sqlite-3.30.1.catalina.bottle.tar.gz
 ==> Caveats
 sqlite is keg-only, which means it was not symlinked into /usr/local,
 because macOS provides an older sqlite3.
 If you need to have sqlite first in your PATH run:
   echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc
 For compilers to find sqlite you may need to set:
   export LDFLAGS="-L/usr/local/opt/sqlite/lib"
   export CPPFLAGS="-I/usr/local/opt/sqlite/include"
 For pkg-config to find sqlite you may need to set:
   export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
 ==> Summary
 🍺  /usr/local/Cellar/sqlite/3.30.1: 11 files, 3.9MB
 ==> Installing python@2
 Warning: Building python@2 from source:
   The bottle needs the Apple Command Line Tools to be installed.
   You can install them, if desired, with:
     xcode-select --install
 ==> Downloading https://www.python.org/ftp/python/2.7.17/Python-2.7.17.tar.xz
 ################################################################## 100.0%
 ==> ./configure --prefix=/usr/local/Cellar/python@2/2.7.17 --enable-ipv6 --datarootdir=/usr/local/Cellar/py
 ==> make
==> make install PYTHONAPPSDIR=/usr/local/Cellar/python@2/2.7.17
 ==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python@2/2.7.17/share/python@2
 ==> Downloading https://files.pythonhosted.org/packages/f4/d5/a6c19dcbcbc267aca376558797f036d9bcdff344c9f78
 ################################################################## 100.0%
 ==> Downloading https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df71a14
 ################################################################## 100.0%
 ==> Downloading https://files.pythonhosted.org/packages/59/b0/11710a598e1e148fb7cbf9220fd2a0b82c98e94efbdec
 ################################################################## 100.0%
 ==> /usr/local/Cellar/python@2/2.7.17/bin/python -s setup.py --no-user-cfg install --force --verbose --sing
 ==> /usr/local/Cellar/python@2/2.7.17/bin/python -s setup.py --no-user-cfg install --force --verbose --sing
 ==> /usr/local/Cellar/python@2/2.7.17/bin/python -s setup.py --no-user-cfg install --force --verbose --sing
 ==> Caveats
 Pip and setuptools have been installed. To update them
   pip install --upgrade pip setuptools
 You can install Python packages with
   pip install 
 They will install into the site-package directory
   /usr/local/lib/python2.7/site-packages
 See: https://docs.brew.sh/Homebrew-and-Python
 ==> Summary
 🍺  /usr/local/Cellar/python@2/2.7.17: 6,645 files, 91.4MB, built in 4 minutes 16 seconds
 ==> Caveats
 ==> sqlite
 sqlite is keg-only, which means it was not symlinked into /usr/local,
 because macOS provides an older sqlite3.
 If you need to have sqlite first in your PATH run:
   echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc
 For compilers to find sqlite you may need to set:
   export LDFLAGS="-L/usr/local/opt/sqlite/lib"
   export CPPFLAGS="-I/usr/local/opt/sqlite/include"
 For pkg-config to find sqlite you may need to set:
   export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
 ==> python@2
 Pip and setuptools have been installed. To update them
   pip install --upgrade pip setuptools
 You can install Python packages with
   pip install 
 They will install into the site-package directory
   /usr/local/lib/python2.7/site-packages
 See: https://docs.brew.sh/Homebrew-and-Python

Python Crashing Hard

Next, on Ansible version check I got another error

➜  trellis git:(master) ansible --version    
[1]    19153 abort      ansible --version

It was somehow crashing Python 2.7 though it should just work with it. I decided to upgrade Ansible as well

➜  ~ sudo pip install ansible --upgrade
.....
Requirement already satisfied, skipping upgrade: six>=1.4.1 in /usr/local/lib/python2.7/site-packages (from cryptography->ansible) (1.11.0)
 Requirement already satisfied, skipping upgrade: pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography->ansible) (2.18)
 Installing collected packages: ansible
   Found existing installation: ansible 2.7.5
     Uninstalling ansible-2.7.5:
       Successfully uninstalled ansible-2.7.5
 Successfully installed ansible-2.9.1

Still I had the Python error and iTerm was showing a MacOS popup that Python was crashing unexpectedly:

Python quit unexpectedly.
Click Reopen to open the application again. Click Report to see more detailed information and send a report to Apple.
Application Specific Information:
 /usr/lib/libcrypto.dylib
 abort() called
 Invalid dylib load. Clients should not load the unversioned libcrypto dylib as it does not have a stable ABI.

Invalid DyLib

Found https://stackoverflow.com/questions/58272830/python-crashing-on-macos-10-15-beta-19a582a-with-usr-lib-libcrypto-dylib on the error with the Dynamic library loaded being the wrong one and decided to install openssl

brew install openssl

But it was already installed so no need for that. So then I added this line to .zshrc to load the correct library inside zsh:

# Python crash fix
export DYLD_LIBRARY_PATH=/usr/local/opt/openssl/lib:$DYLD_LIBRARY_PATH

All Working

And then restarted iTerm and once I had done that I was in the clear

➜  ~ ansible --version
ansible 2.9.1
config file = None
configured module search path = [u'/Users/jasper/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.17 (default, Nov 17 2019, 10:31:11) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.12)]

I was also able to view the encrypted content again using

ansible-vault view group_vars/all/vault.yml

Will definitely upgrade the Trellis package soon so I can work with Python 3 as next year Python 2 will be completely abandoned. But for now I can work with this setup.

2 Responses

Leave a Reply

Your email address will not be published. Required fields are marked *