由于环境错误而无法安装软件包:[Errno 13]-Python 实用宝典

由于环境错误而无法安装软件包:[Errno 13]

在我的MacOS Mojave终端中,我想使用pip安装python软件包。最后说: You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. 所以我想用给定的命令更新点子,但出现错误: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO' Consider using the `--user` option or check the permissions. 我真的不知道该怎么办。我也意识到它在错误消息中说Python 2.7,但是我已经并且只想使用python 3。

问题:由于环境错误而无法安装软件包:[Errno 13]

在我的MacOS Mojave终端中,我想使用pip安装python软件包。最后说:

You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

所以我想用给定的命令更新点子,但出现错误:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 
'/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.

我真的不知道该怎么办。我也意识到它在错误消息中说Python 2.7,但是我已经并且只想使用python 3。

In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:

You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

So I wanted to update pip with the given command but I got an error:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 
'/Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.

I don't really understand what to do now. Also I realized it says Python 2.7 in the error message but I have and want to use only python 3.


回答 0

如果要使用python3 +安装软件包,则需要使用pip3 install package_name

要解决errno 13,您必须--user在末尾添加

pip3 install package_name --user

编辑:

对于python中的任何项目,强烈建议Virtual enviroment上工作,该工具可通过为它们创建隔离的python虚拟环境来帮助将不同项目所需的依赖项分开。

为了使用python3 +创建一个,您必须使用以下命令:

virtualenv enviroment_name -p python3

然后只需激活它就可以对其进行处理:

source enviroment_name/bin/activate

激活虚拟环境后,虚拟环境的名称将显示在终端的左侧。这将使您知道虚拟环境当前处于活动状态。现在,您只需使用即可在该虚拟环境中安装与项目相关的依赖项pip

pip install package_name

If you want to use python3+ to install the packages you need to use pip3 install package_name

And to solve the errno 13 you have to add --user at the end

pip3 install package_name --user

EDIT:

For any project in python it's highly recommended to work on a Virtual enviroment, is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them.

In order to create one with python3+ you have to use the following command:

virtualenv enviroment_name -p python3

And then you work on it just by activating it:

source enviroment_name/bin/activate

Once the virtual environment is activated, the name of your virtual environment will appear on left side of terminal. This will let you know that the virtual environment is currently active. Now you can install dependencies related to the project in this virtual environment by just using pip.

pip install package_name

回答 1

关于权限命令,请尝试在终端命令前使用sudo:

sudo pip install --upgrade pip

Sudo允许您使用超级用户的特权运行命令,并将为全局,系统范围的Python安装安装软件包。理想情况下,您应该为正在处理的项目创建一个虚拟环境。看看这个

关于python尝试将pip作为可执行文件运行,如下所示:

python3.6 -m pip install <package>

Regarding the permissions command, try using sudo in front of your terminal command:

sudo pip install --upgrade pip

Sudo is a program that allows you to run the command with the privileges of the superuser.

Regarding the python Try running pip as an executable like this:

python3.6 -m pip install <package>

回答 2

我犯了同样的错误,然后意识到我已经以root用户身份创建了虚拟环境。它已被写保护,因此请检查您的虚拟环境是否被写保护。制作新的venv,然后重试

I was making the same mistakes then I realized that I have created my virtual environment as root user. It was write protected, so please check whether your virtual environment is write protected. make a new venv and try again


回答 3

尝试安装软件包时(烧瓶类),我遇到了相同的错误。
我犯了以root身份安装anaconda的错误。我更改了已安装的anaconda文件夹的所有权,并且可以成功安装该软件包。

使用chown带选项的命令-R来递归地更改已安装的anaconda文件夹的所有权,如下所示:

chown -R owner:group /path/to/anaconda

在这里所有者是您的用户名,组是组名。

I got the same error when I was trying to install a package (flask-classful).
I made the mistake of installing anaconda as root. I changed the ownership of the installed anaconda folder and I could install the package successfully.

Use the command chown with option -R to recursively change ownership of the installed anaconda folder like so:

chown -R owner:group /path/to/anaconda

Here owner is your username and group is the group name.


回答 4

答案在错误消息中。过去,您或某个进程执行sudo pip,并且导致该目录下的某些目录/Library/Python/2.7/site-packages/...具有权限,导致当前用户无法访问该目录。

然后您做了一个pip install whatever依赖另一件事的。

因此,要对其进行修复,请访问/Library/Python/2.7/site-packages / ...并找到具有root或not-your-user权限的目录,然后删除然后重新安装这些软件包,或者只是强制对用户拥有所有权应该接触的人。

The answer is in the error message. In the past you or a process did a sudo pip and that caused some of the directories under /Library/Python/2.7/site-packages/... to have permissions that make it unaccessable to your current user.

Then you did a pip install whatever which relies on the other thing.

So to fix it, visit the /Library/Python/2.7/site-packages/... and find the directory with the root or not-your-user permissions and either remove then reinstall those packages, or just force ownership to the user to whom ought to have access.


回答 5

使用进行安装时numpy,我遇到了同样的问题pip install numpy

然后我尝试

sudo -H pip3 install --upgrade pip

sudo -H pip3 install numpy

对我来说效果很好。

说明:-H带(HOME)选项sudo设置HOME环境变量设置为目标用户(root默认情况下)的主目录。默认情况下,sudo不会修改HOME。

I had the same problem while installing numpy with pip install numpy.

Then I tried

sudo -H pip3 install --upgrade pip

sudo -H pip3 install numpy

It worked well for me.

Explanation : The -H (HOME) option with sudo sets the HOME environment variable to the home directory of the target user (root by default). By default, sudo does not modify HOME.


回答 6

对于MacO和Unix

只需在命令中添加sudo即可,因为它将以超级用户身份运行。

sudo pip install --upgrade pip

建议您不要直接这样做-请参阅这篇文章

For MacOs & Unix

Just by adding sudo to command will work, as it would run it as a superuser.

sudo pip install --upgrade pip

It is advised that you should not directly do it though - please see this post


回答 7

这为我工作:

 python3 -m venv env
 source ./env/bin/activate
 python -m pip install package

(来自Github:https : //github.com/googlesamples/assistant-sdk-python/issues/236

This worked for me:

 python3 -m venv env
 source ./env/bin/activate
 python -m pip install package

(From Github: https://github.com/googlesamples/assistant-sdk-python/issues/236 )


回答 8

我已经尝试过此处发布的所有建议,但仍收到errno 13

我正在使用Windows,而我的python版本是3.7.3

经过5小时的尝试解决后,此步骤对我有用:

我尝试以管理员身份运行以打开命令提示符

I already tried all suggestion posted in here, yet I'm still getting the errno 13,

I'm using Windows and my python version is 3.7.3

After 5 hours of trying to solve it, this step worked for me:

I try to open the command prompt by run as administrator


回答 9

我也遇到了同样的问题,我尝试了许多不同的命令行,这对我有用:

尝试:

    conda install py-xgboost

那就是我得到的:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

I also had the same problem, I tried many different command lines, this one worked for me:

Try:

    conda install py-xgboost

That's what I got:

Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: /home/simplonco/anaconda3

  added / updated specs:
    - py-xgboost


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _py-xgboost-mutex-2.0      |            cpu_0           9 KB
    ca-certificates-2019.1.23  |                0         126 KB
    certifi-2018.11.29         |           py37_0         146 KB
    conda-4.6.2                |           py37_0         1.7 MB
    libxgboost-0.80            |       he6710b0_0         3.7 MB
    mkl-2019.1                 |              144       204.6 MB
    mkl_fft-1.0.10             |   py37ha843d7b_0         169 KB
    mkl_random-1.0.2           |   py37hd81dba3_0         405 KB
    numpy-1.15.4               |   py37h7e9f1db_0          47 KB
    numpy-base-1.15.4          |   py37hde5b4d6_0         4.2 MB
    py-xgboost-0.80            |   py37he6710b0_0         1.7 MB
    scikit-learn-0.20.2        |   py37hd81dba3_0         5.7 MB
    scipy-1.2.0                |   py37h7c811a0_0        17.7 MB
    ------------------------------------------------------------
                                           Total:       240.0 MB

The following NEW packages will be INSTALLED:

  _py-xgboost-mutex  pkgs/main/linux-64::_py-xgboost-mutex-2.0-cpu_0
  libxgboost         pkgs/main/linux-64::libxgboost-0.80-he6710b0_0
  py-xgboost         pkgs/main/linux-64::py-xgboost-0.80-py37he6710b0_0

The following packages will be UPDATED:

  ca-certificates     anaconda::ca-certificates-2018.12.5-0 --> pkgs/main::ca-certificates-2019.1.23-0
  mkl                                            2019.0-118 --> 2019.1-144
  mkl_fft                              1.0.4-py37h4414c95_1 --> 1.0.10-py37ha843d7b_0
  mkl_random                           1.0.1-py37h4414c95_1 --> 1.0.2-py37hd81dba3_0
  numpy                               1.15.1-py37h1d66e8a_0 --> 1.15.4-py37h7e9f1db_0
  numpy-base                          1.15.1-py37h81de0dd_0 --> 1.15.4-py37hde5b4d6_0
  scikit-learn                        0.19.2-py37h4989274_0 --> 0.20.2-py37hd81dba3_0
  scipy                                1.1.0-py37hfa4b5c9_1 --> 1.2.0-py37h7c811a0_0

The following packages will be SUPERSEDED by a higher-priority channel:

  certifi                                          anaconda --> pkgs/main
  conda                                            anaconda --> pkgs/main
  openssl                anaconda::openssl-1.1.1-h7b6447c_0 --> pkgs/main::openssl-1.1.1a-h7b6447c_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
libxgboost-0.80      | 3.7 MB    | ##################################### | 100% 
mkl_random-1.0.2     | 405 KB    | ##################################### | 100% 
certifi-2018.11.29   | 146 KB    | ##################################### | 100% 
ca-certificates-2019 | 126 KB    | ##################################### | 100% 
conda-4.6.2          | 1.7 MB    | ##################################### | 100% 
mkl-2019.1           | 204.6 MB  | ##################################### | 100% 
mkl_fft-1.0.10       | 169 KB    | ##################################### | 100% 
numpy-1.15.4         | 47 KB     | ##################################### | 100% 
scipy-1.2.0          | 17.7 MB   | ##################################### | 100% 
scikit-learn-0.20.2  | 5.7 MB    | ##################################### | 100% 
py-xgboost-0.80      | 1.7 MB    | ##################################### | 100% 
_py-xgboost-mutex-2. | 9 KB      | ##################################### | 100% 
numpy-base-1.15.4    | 4.2 MB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

回答 10

MacOS上尝试以下命令行,以检查用户的权限。

$ sudo python -m pip install --user --upgrade pip

try this command line below for MacOS to check user's permission.

$ sudo python -m pip install --user --upgrade pip

回答 11

我为Python 3安装了anaconda。我的mac也有Python2。

python --version

给我

的Python 3.7.3

python2.7 --version

给我

Python 2.7.10

我想在python2中安装pyspark软件包,因为它已经安装在python3中。

python2.7 -m pip install pyspark

给我一个错误

由于环境错误而无法安装软件包:[Errno 13]权限被拒绝:'/Library/Python/2.7/site-packages/pyspark'考虑使用该--user选项或检查权限。

下面的命令解决了它。谢谢上帝,我不必做任何配置更改。

python2.7 -m pip install pyspark --user

收集pyspark的要求已经满足:/Library/Python/2.7/site-packages中的py4j == 0.10.7(来自pyspark)(0.10.7)安装收集的软件包:pyspark成功安装pyspark-2.4.4您正在使用pip版本18.1。 ,但是版本19.3.1可用。您应该考虑通过“ pip install --upgrade pip”命令进行升级。

I have anaconda installed for Python 3. I also have Python2 in my mac.

python --version

gives me

Python 3.7.3

python2.7 --version

gives me

Python 2.7.10

I wanted to install pyspark package in python2, given that it was already installed in python3.

python2.7 -m pip install pyspark

gives me an error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pyspark' Consider using the --user option or check the permissions.

The below command solved it. Thank god I didn't have to do any config changes.

python2.7 -m pip install pyspark --user

Collecting pyspark Requirement already satisfied: py4j==0.10.7 in /Library/Python/2.7/site-packages (from pyspark) (0.10.7) Installing collected packages: pyspark Successfully installed pyspark-2.4.4 You are using pip version 18.1, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.


回答 12

我在具有所有正确权限的linux上已安装NTFS分区上的venv中遇到了类似的麻烦。确保使用--ignore-installed运行了pip可以解决该问题,即:

python -m pip install --upgrade --ignore-installed

I had similar trouble in a venv on a mounted NTFS partition on linux with all the right permissions. Making sure pip ran with --ignore-installed solved it, i.e.:

python -m pip install --upgrade --ignore-installed


回答 13

在Mac上,没有3.7目录,或者目录3.7归拥有root。因此,我删除了该目录,由当前用户创建了一个新目录,并将其移至该目录。然后安装完成,没有错误。

sudo rm -rf /Library/Python/3.7
mkdir 3.7
sudo mv 3.7 /Library/Python
ll /Library/Python/
pip3 install numpy

On Mac, there is no 3.7 directory or the directory 3.7 is owned by root. So, I removed that directory, create a new directory by current user, and move it there. Then installation finishes without error.

sudo rm -rf /Library/Python/3.7
mkdir 3.7
sudo mv 3.7 /Library/Python
ll /Library/Python/
pip3 install numpy

回答 14

当我尝试安装opencv-python软件包时,也会发生这种情况:

安装尝试

我可以用命令行修复它

python3 -m pip install {name of package} --user

当我尝试安装上述软件包时,命令变为:

python3 -m pip install opencv-python --user

结果是:

结果

This also happens to me when I try to install the opencv-python package:

installation attempt

I can fix it with command line

python3 -m pip install {name of package} --user

When I try to install the said package, the command becomes:

python3 -m pip install opencv-python --user

Resulting in this:

result


回答 15

只是 sudo pip install packagename

just sudo pip install packagename


本文由 Python 实用宝典 作者:Python实用宝典 发表,其版权均为 Python 实用宝典 所有,文章内容系作者个人观点,不代表 Python 实用宝典 对观点赞同或支持。如需转载,请注明文章来源。
21

抱歉,评论已关闭!