Pip install not to site-packages directory

I have installed Python 3.7.5 on MacOS 10.14.6 from brew (brew install python). brew info python shows:

You can install Python packages with
pip3 install
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages

But when I trying install boto3 pip package (actually name of package no matter, it’s issue with any) see this error:

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/lib/python3.7'
Consider using the `--user` option or check the permissions.

I tried figure out where pip get ‘/lib/python3.7’ lib, because python itself shows site-packages is another directory:
python3 -c “import site; print(site.getsitepackages())”
[‘/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages’]

And also this directory not listed here:
python3 -m site
sys.path = [
‘/usr/local/lib/python3.7/site-packages’,
‘/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python37.zip’,
‘/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7’,
‘/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload’,
‘/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages’,
]

Please help determine a way how pip determine where packages should be installed.

1 Like

pip, on your system, appears to resolve to a different command, associated with a different Python installation. Verify your PATH or at least if which pip gives you the correct full path.

You can always:

  • use the full path: /usr/local/bin/pip
  • use python3 -m pip instead of pip to use the module installed with a specific Python binary.
1 Like

Thank you for quick response Martijn!

It was my first option - try setup by invoke module directly. But result was the same.

I spent yesterday 4 hours for this problem but now eventually find out the answer - it was due to file in my home directory:
cat ~/.pydistutils.cfg
[install]
prefix=

I no have idea how it was and for what created but deletion it resolve the problem. I will check for what this file used.

1 Like