Permission denied error by installing matplotlib

115,249

Solution 1

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:

  1. Right click on the Command Prompt icon
  2. Select the option Run This Program As An Administrator
  3. Run the command pip install <package>

Solution 2

I solved this issue by typing the following command,

pip install --user <package_name>

Example,

pip install --user tensorflow

NOTE: You should not enter your own username for this command. Please enter with '--user'.

Solution 3

Try this:

sudo pip install matplotlib

Solution 4

You don't have the permission to install a package globally, so you can use sudo pip install matplotlib, but it isn't recommended.

The recommended way is using venv or virtualenv to create a virtual environment.

venv:

  1. Create a python virtual environment, command: python3 -m venv <DIR>
  2. Activate the virtual environment, command: source <DIR>/bin/activate
  3. Install matplotlib, command: pip install matplotlib
Share:
115,249
Maximilian von Unwerth
Author by

Maximilian von Unwerth

Updated on July 09, 2022

Comments

  • Maximilian von Unwerth
    Maximilian von Unwerth almost 2 years

    I installed opencv with all dependencies. After the installation I tried to import matplotlib for a simple example.

    Then I got the following error, when I tried to install matplotlib via pip with pip install matplotlib:

    Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/kiwisolver.cpython-35m-x86_64-linux-gnu.so'
    Consider using the `--user` option or check the permissions.
    

    What can I do to install matplotlib?