1

I believe the python environment is my Mac is a little bit mess up... Every time I use brew, it will first do this:

==> Migrating python3 to python
==> Unlinking python3
==> Unlinking python
Error: Error occurred while migrating.
Permission denied @ unlink_internal - /usr/local/share/python
Backing up...
Error: Permission denied @ unlink_internal - /usr/local/share/python

in my mac, I have:

  • python2, which is referred by 'python', and it's installed by anaconda bundle.
  • python3, which is referred by 'python3', and it's installed by brew.

Actually I create a symbolic link in /usr/local/bin for python3, which is the best way I can figure out to distinguish python/python3 in my machine......but recently it's just messed up...

I tried find / -name "python3", and here is the result:

/Users/liuziqi/anaconda/lib/python2.7/site-packages/astroid/tests/testdata/python3
/Users/liuziqi/google-cloud-sdk/.install/.backup/platform/gsutil/third_party/crcmod/python3
/Users/liuziqi/google-cloud-sdk/.install/.backup/platform/gsutil/third_party/httplib2/python3
/Users/liuziqi/google-cloud-sdk/platform/gsutil/third_party/crcmod/python3
/Users/liuziqi/google-cloud-sdk/platform/gsutil/third_party/httplib2/python3
/usr/local/Cellar/python3
/usr/local/Cellar/python3/3.6.1/bin/python3
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/bin/python3
/usr/local/Cellar/python3/3.6.4_2/bin/python3
/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/bin/python3
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Aliases/python3
/usr/local/lib/python3.6/site-packages/astroid/tests/testdata/python3
/usr/local/opt/python3

the python3 I previously used is /usr/local/Cellar/python3/3.6.1/bin/python3, and I created a link to /usr/local/bin

Ziqi Liu
  • 2,931
  • 5
  • 31
  • 64
  • Firstly, do you need to have both Python 2 and 3 on your machine? secondly, when you run `ls -la /usr/local/share/ | grep python`, who owns this file? It seems like Brew don't have permission to remove the file. – Prav Mar 03 '18 at 22:58
  • To be fair I should've asked this before. What are you trying to do? Are you trying to upgrade Python? – Prav Mar 03 '18 at 23:03
  • I do need both python2 and python3. Actually I'm not doing anything with python, the problem is that when I use brew to install something else, it will first trying migrating python (maybe the that package have some dependency on python). – Ziqi Liu Mar 03 '18 at 23:38
  • when i run `ls -la /usr/local/share/ | grep python`, the result is `lrwxr-xr-x 1 liuziqi admin 38 1 11 03:45 python -> ../Cellar/python/2.7.14_2/share/python` – Ziqi Liu Mar 03 '18 at 23:38

1 Answers1

1

You have to fix the permissions with:

sudo chown -R "$USER":admin /usr/local
sudo chown -R "$USER":admin /Library/Caches/Homebrew

It works well, if you are the only Homebrew user on the system. It could cause problems if third party tools are waiting other permissions on /usr/local. But, I use this settings for years without problems. See How to fix homebrew permissions? for details.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240