Tag: macOS

Install mysqlclient for Django 1.10 on macOS

I was trying to get a fresh Django 1.10 project setup on macOS Sierra using MySQL and Python 3.5 in a venv but pip install mysqlclient was failing with the error:

ld: library not found for -lssl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: command 'clang' failed with exit status 1

As is often the case after some searching I came into the solution on Stack Overflow. mysqlclient needs to link against the homebrew version of openssl I have installed:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient

The solution post also mentions that installing the xcode command line tools via:

xcode-select --install

will provide the required ssl libs for the system installed version of python (2.7 on Sierra), it will not work for python in a virtual environment.


cd shortcuts with CDPATH and bash tab completion

For years I've had some fairly hacky ways of changing directories quicker. I'd wager a nickel these kind of aliases are pretty common:

alias cdblog='cd ~/sites/my_blog'
alias cdapp='cd ~/repos/my_app'

That grows pretty unwieldy when working with a bunch of repos. So then I thought I was super clever by using bash functions to cd directly into a git repo, since all my repos were in one of two parent dirs:

function repos(){ cd ~/repos/$1; }
function sites(){ cd ~/sites/$1; }

me@local$ repo my_app
me@local$ sites my_blog

It was a bit more typing, but fewer aliases to remember and more scalable. However the loss of tab completion using this method is a bummer.

When I finally got annoyed enough to look for a better way, of course it was waiting for me in a superuser post. Using the CDPATH environment variable and the bash-completion package (same name on centos/fedora/os x/ubuntu) I can now cd into my most used directories, complete with tab completion, from anywhere on the cli.

  1. Install bash-completion, substituting appropriate package manager:

    brew install bash-completion
    
  2. OS X ONLY: append to your ~/.bash_profile:

    if [ -f $(brew --prefix)/etc/bash_completion ]; then
      . $(brew --prefix)/etc/bash_completion
    fi
    
  3. Everyone append to your ~/.bash_profile:

    export CDPATH=.:~:~/repos:~/sites
    
  4. Activate changes:

    source ~/.bash_profile
    
  5. Kick the tires, from say /tmp:

    me@local tmp$ cd my<TAB><TAB>
    my_blog/ my_app/
    

Tab completion should be working as you'd expect against all your favorite directories, no matter where you are on the cli. This made navigating around dozens of repos quite a bit easier for me, though for a handful of my most used ones I may still treat myself to a dedicated alias. Because I'm weak.

© Justin Montgomery. Built using Pelican. Theme is subtle by Carey Metcalfe. Based on svbhack by Giulio Fidente.