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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50087098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:23:31  来源:igfitidea点击:

Permission denied error by installing matplotlib

pythonopencvmatplotlibpipfailed-installation

提问by Maximilian von Unwerth

I installed opencvwith all dependencies. After the installation I tried to import matplotlibfor a simple example.

我安装了带有所有依赖项的opencv。安装后,我尝试导入matplotlib作为一个简单示例。

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

然后,当我尝试通过 pip 安装 matplotlib 时出现以下错误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?

我可以做什么来安装 matplotlib?

回答by Ronan Boiteau

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 suor sudofrom your terminal, to install the package as root:

您可以使用susudo从您的终端将软件包安装为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>
  1. 右键单击命令提示符图标
  2. 选择选项 Run This Program As An Administrator
  3. 运行命令 pip install <package>

回答by Deepu Mayanattanmy

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'。

回答by Ishara Madhawa

Try this:

尝试这个:

sudo pip install matplotlib

回答by ajourney

Try this:

尝试这个:

sudo pip install <xyz>

And/Or this:

和/或这个:

sudo pip3 install <xyz>

回答by Fishdou

You haven't the permission to install a package globally, you can use sudo pip install matplotlib, but it wasn't recommended.

您没有全局安装包的权限,您可以使用sudo pip install matplotlib,但不建议这样做。

The recommended way is using venvor virtualenvto create a virtual environment.

推荐的方式是使用venvvirtualenv创建虚拟环境。

venv:
1.creat a python virtual environmentpython3 -m venv <DIR>
2.activate the virtual environmentsource <DIR>/bin/activate
3.install matplotlib,pip install matplotlib

venv:
1.创建python虚拟环境python3 -m venv <DIR>
2.激活虚拟环境source <DIR>/bin/activate
3.安装matplotlib,pip install matplotlib