156

While installing pip and python I have ran into a that says:

The directory '/Users/Parthenon/Library/Logs/pi' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want the -H flag.

because I now have to install using sudo.

I had python and a handful of libraries already installed on my Mac, I'm running Yosemite. I recently had to do a clean wipe and then reinstall of the OS. Now I'm getting this prompt and I'm having trouble figuring out how to change it

Before my command line was Parthenon$ now it's Philips-MBP:~ Parthenon$

I am the sole owner of this computer and this is the only account on it. This seems to be a problem when upgrading to python 3.4, nothing seems to be in the right place, virtualenv isn't going where I expect it to, etc.

Gautam Savaliya
  • 1,403
  • 2
  • 20
  • 31
Max Phillips
  • 6,991
  • 9
  • 44
  • 71
  • Is your account name Philip? – komaromy Jan 09 '15 at 22:08
  • I just noticed this happening when using pip on my own machine yesterday, what do you mean by virtualenv is not going where you expect it to? – Padraic Cunningham Jan 09 '15 at 22:17
  • I installed Python 3.4 on my machine, yet when I run python in my terminal it still runs 2.7 even after going through the whole install process. I only mentioned virtualenv because I would typically expect to find it in Library/Python/3.4 but there is no Library/Python/3.4 – Max Phillips Jan 09 '15 at 22:21
  • you need to use something like python3 or python3.4 to use the python3 interpreter, the items being reopened is just a setting, ubuntu has the same option. – Padraic Cunningham Jan 09 '15 at 22:27
  • @PadraicCunningham are you getting the same pip issue though? Did you recently upgrade to Yosemite? – Max Phillips Jan 09 '15 at 23:42
  • That is a warning, it should not prevent you from installing any packages, what else is wrong? Unless you had permissions you would always have had to use sudo to install packages globally – Padraic Cunningham Jan 10 '15 at 00:10
  • [this](https://github.com/pypa/pip/issues/2285) is a good explanation. – dashesy Nov 04 '16 at 20:04

5 Answers5

128

I also saw this change on my Mac when I went from running pip to sudo pip. Adding -H to sudo causes the message to go away for me. E.g.

sudo -H pip install foo

man sudo tells me that -H causes sudo to set $HOME to the target users (root in this case).

So it appears pip is looking into $HOME/Library/Log and sudo by default isn't setting $HOME to /root/. Not surprisingly ~/Library/Log is owned by you as a user rather than root.

I suspect this is some recent change in pip. I'll run it with sudo -H for now to work around.

Von
  • 4,365
  • 2
  • 29
  • 29
  • 20
    Please note that using `sudo pip` is totally incorrect. For more information please refer here http://stackoverflow.com/questions/33004708/osx-el-capitan-sudo-pip-install-oserror-errno-1-operation-not-permitted/33004920#33004920 – Mikko Ohtamaa Nov 25 '15 at 18:38
  • I had the same problem, but yeah now I have to install using the "-H" flag. – Malachi Bazar Jul 28 '16 at 13:25
63

What is the problem here is that you somehow installed into virtualenv using sudo. Probably by accident. This means root user will rewrite Python package data, making all file owned by root and your normal user cannot write those files anymore. Usually virtualenv should be used and owned by your normal UNIX user only.

You can fix the issue by changing UNIX file permissions pack to your user. Try:

$ sudo chown -R USERNAME /Users/USERNAME/Library/Logs/pip
$ sudo chown -R USERNAME /Users/USERNAME/Library/Caches/pip

then pip should be able to write those files again.

More information about UNIX file permission management

Thomasleveil
  • 95,867
  • 15
  • 119
  • 113
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
  • Pip still writes with the error. I also have a similar warning and my permissions are correct, the OP is not actually using a virtualenv so it would make sense that installing packages globally would require sudo. – Padraic Cunningham Jan 10 '15 at 01:08
  • 1
    @PadraicCunningham: If pip gives an error that your permissions are incorrect, please show your file permissions, so we can figure out what's wrong with them. Otherwise helping would be a shot in the dark. – Mikko Ohtamaa Jan 10 '15 at 01:13
  • Also I suggest you open an another question because your issue might be different what the original author has – Mikko Ohtamaa Jan 10 '15 at 01:15
  • Using my own username, I received an error: Input: sudo chown -R USERNAME /Users/USERNAME/Library/Logs/pip Output: chown: /Users/USERNAME/Library/Logs/pip: No such file or directory – debtitor Feb 24 '19 at 12:30
61

pip install --user <package name> (no sudo needed) worked for me for a very similar problem.

SiHa
  • 7,830
  • 13
  • 34
  • 43
Safwan
  • 3,300
  • 1
  • 28
  • 33
0

basic info

  • system: mac os 18.0.0
  • current user: yutou

the key

  1. add the current account to wheel group
sudo dscl . -append /Groups/wheel wheel $(whoami)
  1. modify python package mode to 775.
chmod -R 775 ${this_is_your_python_package_path}

the whole thing

  • when python3 compiled well, the infomation is just like the question said.
  • I try to use pip3 install requests and got:
File "/usr/local/python3/lib/python3.6/os.py", line 220, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: 
'/usr/local/python3/lib/python3.6/site-packages/requests'
  • so i cd /usr/local/python3/lib/python3.6/site-packages, then ls -al and got:
drwxr-xr-x    6 root   wheel   192B  2 27 18:06 requests/

when i saw this, i understood, makedirs is an action of write, but the requests mode drwxrwxr-x displaied only user root can write the requests file. If add yutou(whoami) to the group wheel, and modify the package to the group wheel can write, then i can write, and the problem solved.

How to add yutou to group wheel? + detect group wheel, sudo dscl . -list /groups GroupMembership, you will find:

wheel                    root

the group wheel only one member root. + add yutou to group wheel, sudo dscl . -append /Groups/wheel wheel yutou. + check, sudo dscl . -list /groups GroupMembership:

wheel                    root yutou

modify the python package mode

chmod -R 775 /usr/local/python3/lib/python3.6
0

If you altered your $PATH variable that could also cause the problem. If you think that might be the issue, check your ~/.bash_profile or ~/.bashrc

jeffhale
  • 3,759
  • 7
  • 40
  • 56