简体   繁体   English

安装 matplotlib 导致权限被拒绝错误

[英]Permission denied error by installing matplotlib

I installed opencv with all dependencies.我安装了带有所有依赖项的opencv After the installation I tried to import matplotlib for a simple example.安装后,我尝试导入matplotlib作为一个简单示例。

Then I got the following error, when I tried to install matplotlib via pip with pip install matplotlib :然后,当我尝试使用pip install matplotlib通过 pip 安装 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?我可以做什么来安装 matplotlib?

Looks like your user doesn't 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 和 Windows 解决此问题的方法。


Linux / macOS 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 :您可以从终端使用susudoroot身份安装软件包

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选择选项Run This Program As An Administrator身份Run This Program As An Administrator
  3. Run the command pip install <package>运行命令pip install <package>

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'.请输入'--user'。

尝试这个:

sudo pip install matplotlib

You don't have the permission to install a package globally, so you can use sudo pip install matplotlib , but it isn't recommended.您没有全局安装包的权限,因此您可以使用sudo pip install matplotlib ,但不建议这样做。

The recommended way is using venv or virtualenv to create a virtual environment.推荐的方式是使用venvvirtualenv创建虚拟环境。

venv:静脉:

  1. Create a python virtual environment, command: python3 -m venv <DIR>创建python虚拟环境,命令: python3 -m venv <DIR>
  2. Activate the virtual environment, command: source <DIR>/bin/activate激活虚拟环境,命令: source <DIR>/bin/activate
  3. Install matplotlib, command: pip install matplotlib安装matplotlib,命令: pip install matplotlib

Try this: 尝试这个:

sudo pip install <xyz>

And/Or this: 和/或这个:

sudo pip3 install <xyz>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM