To fix pip install failing with: OSError: [Errno 13] Permission denied on directory with Python, we can create a virtualenv in a folder where we have permission to write files.
To do this, we run
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
where venv
is a folder that we can write files to.
And then we activate the virtualenv with
source venv/bin/activate
And then we install the packages into the virtualenv with
pip install -r requirements.txt
We can also install the packages into our home directory with
pip install --user -r requirements.txt