Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing psutil libraray with pip on OSX for Python

I am new to python, and I have become interested in learning more about th efficiency of my functions. For example using generators vs. normal getter functions returning lists. I heard that you can measure the memory used by your python program by using the following code.

import psutil
print(psutil.virtual_memory())

I installed pip successfully, but i am unable to install psutil using the following command on terminal

pip install psutil

I get the following error

cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.12-intel-2.7/psutil/_psutil_posix.o -o build/lib.macosx-10.12-intel-2.7/psutil/_psutil_posix.so running install_lib creating /Library/Python/2.7/site-packages/psutil error: could not create '/Library/Python/2.7/site-packages/psutil': Permission denied

There was more text before this. It seems to me there is some sort of permission issue. How do I fix this? I am running Python 3 from Sublime Text Editor. In the error it mentions "creating /Library/Python/2.7/site-packages/psutil".

like image 566
Varun Narayanan Avatar asked Oct 17 '22 07:10

Varun Narayanan


1 Answers

You're trying to install the library in the system python installation. That requires root, and is probably not recommended.

Alternatives:

  1. Install Python yourself, for example via Homebrew - after Homebrew is set up, install Python with brew install python and then pip will work.
  2. Consider private "working copies" of python where you can install any libraries without messing up other installations, for example via virtualenv.
  3. If you just want it working and don't care if it messes up your Python installation later, sudo pip install psutil will run with root privileges and will have write access to those directories. Not recommended.
like image 102
orip Avatar answered Nov 14 '22 23:11

orip