Fix permission errors for pip install.
Fix errors and make build idempotent.