Getting Permission Denied when running pip as root on my Mac
Use a virtual environment:
$ virtualenv myenv
.. some output ..
$ source myenv/bin/activate
(myenv) $ pip install what-i-want
You only use sudo
or elevated permissions when you want to install stuff for the global, system-wide Python installation.
It is best to use a virtual environment which isolates packages for you. That way you can play around without polluting the global python install.
As a bonus, virtualenv does not need elevated permissions.
Permission denied with trying to use pip on MAC?
This is a permissions issue.
Consider using pip install "packagename" --user
as mentioned in the error.
This is covered HERE
Why is permission denied on pip install except for when --user is included at end of command?
With a virtual environment activated,
pip install spam
tries to install into the virtual environment's site-packages. This will almost always be somewhere you have write permissions for.pip install --user spam
tries to install into the user-packages directory. This will always be somewhere under your home directory, so you should always have write permissions for it.pip install spam
tries to install files into the site-packages directory for your Python installation. This will usually not be in your home directory (typically it's somewhere in/Library
), so you may or may not have write permissions.- Apple's pre-installed Python does not give you write permissions to its site-packages.
sudo pip install spam
will let you ignore the permissions by installing as root, although with some Python installations it may cause other problems.
- Homebrew, Python.org, and Anaconda/Miniconda do give you write permissions to their site-packages if you leave the defaults alone.
- Obviously, leave the defaults alone if you know what you're doing.
- Less common ways of installing (Enthought, building from source, MacPorts, etc.), you should read the appropriate docs.
- Apple's pre-installed Python does not give you write permissions to its site-packages.
So, most likely, you're using a third-party Python and/or an active virtual environment on the machines where pip install spam
works, but you're using Apple's pre-installed Python on the ones where it doesn't.
While you could fix that by using sudo
, you probably don't want to, for a few reasons:
- On recent versions of macOS, Apple's pre-installed Python, and the packages they pre-install with it, are badly out of date.
- The pre-installed packages are set up to be maintained with the deprecated
easy_install
rather thanpip
, so getting them up to date can be a huge pain. - If you mess things up too badly, you can break some system scripts that the OS depends on.
- Your changes can be undone by a macOS system update.
So, a better solution is to install Homebrew/Anaconda/Python.org Python if you can, and also use virtual environments when you can and --user
whenever possible when you can't. Any one of these three will solve your problem, but you really should do all of them.
And then, if you accidentally try to install something to Apple's site-packages, you'll get a permissions error—but that's a good thing; it means you didn't actually change anything, so you have nothing to undo.
Permission denied error when trying to install pip in Mac OS X Lion
You are running the curl
(download) command under sudo
, but the python process itself is running without elevated privileges.
Run it like this instead:
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python get-pip.py
Alternatively, use the sudo
command on the python
part of the pipe instead:
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | sudo python
Permission denied error by installing matplotlib
It looks like your user does not have the permission to install packages in your system (for all users). Here's how to fix this problem for Linux, macOS and Windows.
Linux / macOS
From your terminal, you can install the package for your user only, like this:
pip install <package> --user
OR
You can use su
or sudo
from your terminal, to install the package as root
:
sudo pip install <package>
Windows
From the Command Prompt, you can install the package for your user only, like this:
pip install <package> --user
OR
You can install the package as Administrator, by following these steps:
- Right click on the Command Prompt icon
- Select the option
Run This Program As An Administrator
- Run the command
pip install <package>
Related Topics
How to Add an Extra Column to a Numpy Array
What's the Purpose of "Send" Function on Python Generators
How to Initialize a Two-Dimensional Array in Python
String Replace Doesn't Appear to Be Working
Editing Specific Line in Text File in Python
How to Fix Overlapping Annotations/Text
Getting Syntaxerror for Print with Keyword Argument End=' '
From ... Import' VS 'Import .'
How to Convert Surrogate Pairs to Normal String in Python
Django Urls Typeerror: View Must Be a Callable or a List/Tuple in the Case of Include()
Importerror: No Module Named Requests
How to Use Stringio in Python3
How to Create a Guid/Uuid in Python
Sort() and Reverse() Functions Do Not Work
Changing User Agent on Urllib2.Urlopen
Python Strings and Integer Concatenation