简体   繁体   English

由于 EnvironmentError 无法安装软件包:[Errno 13]

[英]Could not install packages due to an EnvironmentError: [Errno 13]

In my MacOS Mojave terminal I wanted to install a python package with pip.在我的 MacOS Mojave 终端中,我想用 pip 安装一个 python 包。 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:所以我想用给定的命令更新 pip 但我得到了一个错误:

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.我也意识到它在错误消息中说 Python 2.7,但我已经并且只想使用 python 3。

If you want to use python3+ to install the packages you need to use pip3 install package_name如果你想使用python3+安装你需要使用pip3 install package_name的包

And to solve the errno 13 you have to add --user at the end并且要解决errno 13您必须在最后添加--user

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.对于 python 中的任何项目,强烈建议Virtual environment 上工作,该工具通过为它们创建隔离的 python 虚拟环境来帮助保持不同项目所需的依赖项分开。

In order to create one with python3+ you have to use the following command:为了使用python3+创建一个,您必须使用以下命令:

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即可在此虚拟环境中安装与项目相关的依赖项。

pip install package_name

Regarding the permissions command, try using sudo in front of your terminal command:关于权限命令,请尝试在终端命令前使用 sudo:

sudo pip install --upgrade pip

Sudo allows you to run the command with the privileges of the superuser and will install the package for the global, system-wide Python installation. Sudo 允许您以超级用户的权限运行该命令,并将为全局、系统范围的 Python 安装安装包。 Ideally, you should create a virtual environment for the project you are working on.理想情况下,您应该为正在处理的项目创建一个虚拟环境。 Have a look at this看看这个

Regarding the python Try running pip as an executable like this:关于 python 尝试将 pip 作为可执行文件运行,如下所示:

python3.6 -m pip install <package>

I was making the same mistakes then I realized that I have created my virtual environment as root user.我犯了同样的错误,然后我意识到我已经以 root 用户身份创建了我的虚拟环境。 It was write protected, so please check whether your virtual environment is write protected.它被写保护了,所以请检查你的虚拟环境是否被写保护。 make a new venv and try again做一个新的venv然后再试一次

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 higher than current user.过去,您或某个进程执行了sudo pip ,这导致/Library/Python/2.7/site-packages/...下的某些目录具有高于当前用户的权限。

Then you did a pip install whatever which modifies a directory you don't have write access to.然后你做了一个pip install whatever修改你没有写权限的目录。

So to fix it, visit the /Library/Python/2.7/site-packages/... find the directory with the root or elevated permissions and either rm -rf yourpackages then reinstall the packages with your user, or just force ownership there to the user to whom ought to have access using chown -R ... or chmod -R ...因此,要修复它,请访问/Library/Python/2.7/site-packages/...找到具有 root 或提升权限的目录,然后rm -rf yourpackages然后与您的用户一起重新安装包,或者只是强制所有权到那里应该使用chown -R ...chmod -R ...访问的用户

I had the same problem while installing numpy with pip install numpy .我在使用pip install numpy安装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).解释 : sudo-H (HOME) 选项将 HOME 环境变量设置为目标用户的主目录(默认为 root)。 By default, sudo does not modify HOME.默认情况下,sudo 不会修改 HOME。

To see if it's actually a problem with permissions run the following to install a package named xxx .要查看是否真的是权限问题,请运行以下命令来安装名为xxx的包。

pip install --user xxx

for eg: to install package bcrypt run,例如:安装包bcrypt运行,

pip install --user bcrypt

I got the same error when I was trying to install a package (flask-classful).当我尝试安装一个包(flask-classful)时,我遇到了同样的错误。
I made the mistake of installing anaconda as root.我错误地将anaconda安装为root。 I changed the ownership of the installed anaconda folder and I could install the package successfully.我更改了已安装 anaconda 文件夹的所有权,我可以成功安装软件包。

Use the command chown with option -R to recursively change ownership of the installed anaconda folder like so:使用带有选项-R的命令chown以递归方式更改已安装 anaconda 文件夹的所有权,如下所示:

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

Here owner is your username and group is the group name.这里所有者是您的用户名,组是组名。

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 ) (来自 Github: https ://github.com/googlesamples/assistant-sdk-python/issues/236)

I was running python3 -m pip install xxx我正在运行python3 -m pip install xxx

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

/Library/Python/3.8 Indicates that python3 I'm using is the system wide python, and hence permission issues. /Library/Python/3.8表示我使用的python3是系统范围的 python,因此存在权限问题。 Solutions involving --user flags and virtual envs are all solving this issue.涉及--user标志和虚拟环境的解决方案都可以解决这个问题。

For me, using brew the most convenient:对我来说,使用 brew 最方便:

brew install python@3.8
brew link python@3.8
which python3

After which python3 -m pip install xxx succeed without problems.之后python3 -m pip install xxx成功没有问题。 Note that sudo should not be used.请注意,不应使用 sudo。

The principle is the same: you are starting a new environment that is less privileged.原理是一样的:您正在开始一个特权较少的新环境。 This implies all the packages you need from the old environment need to be installed again in this new environment.这意味着您需要从旧环境中获得的所有软件包都需要在这个新环境中再次安装。

I guess use the --user flag if you don't want to reinstall everything.如果您不想重新安装所有内容,我想使用--user标志。

I changed the rights of the venv that I was working in since the permissions were missing in the virtual environment subfolders.我更改了我正在使用的 venv 的权限,因为虚拟环境子文件夹中缺少权限。

sudo chmod -R a+rwx testenv

Then I could install an automatically recommended package from within codium.然后我可以从 codium 中安装一个自动推荐的包。

For MacOs & Unix适用于 MacO 和 Unix

Just by adding sudo to command will work, as it would run it as a superuser.只需将 sudo 添加到命令即可,因为它将以超级用户身份运行。

sudo pip install --upgrade pip

It is advised that you should not directly do it though - please see this post建议您不要直接这样做 - 请参阅此帖子

I have anaconda installed for Python 3. I also have Python2 in my mac.我为 Python 3 安装了 anaconda。我的 mac 中也有 Python2。

python --version

gives me给我

Python 3.7.3 Python 3.7.3

python2.7 --version

gives me给我

Python 2.7.10 Python 2.7.10

I wanted to install pyspark package in python2, given that it was already installed in python3.我想在 python2 中安装 pyspark 包,因为它已经安装在 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.由于 EnvironmentError 无法安装软件包:[Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pyspark' 考虑使用--user选项或检查权限。

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.收集 pyspark 要求已经满足:py4j==0.10.7 in /Library/Python/2.7/site-packages (from pyspark) (0.10.7) 安装收集的包:pyspark 成功安装 pyspark-2.4.4 您使用的是 pip 版本 18.1 ,但是版本 19.3.1 可用。 You should consider upgrading via the 'pip install --upgrade pip' command.您应该考虑通过“pip install --upgrade pip”命令进行升级。

I already tried all suggestion posted in here, yet I'm still getting the errno 13,我已经尝试过这里发布的所有建议,但我仍然得到 errno 13,

I'm using Windows and my python version is 3.7.3我正在使用 Windows,我的 python 版本是 3.7.3

After 5 hours of trying to solve it, this step worked for me:经过 5 个小时的尝试解决后,这一步对我有用:

I try to open the command prompt by run as administrator我尝试以管理员身份运行打开命令提示符

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

尝试: pip install --upgrade pip --user

试试下面这个命令行,让MacOS检查用户的权限。

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

I had similar trouble in a venv on a mounted NTFS partition on linux with all the right permissions.我在具有所有正确权限的 Linux 上安装的 NTFS 分区上的 venv 中遇到了类似的问题。 Making sure pip ran with --ignore-installed solved it, ie:确保 pip 运行--ignore-installed解决了它,即:

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

On Mac, there is no 3.7 directory or the directory 3.7 is owned by root .在 Mac 上,没有3.7目录或目录3.7root拥有。 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

This also happens to me when I try to install the opencv-python package:当我尝试安装opencv-python包时,也会发生这种情况:

安装尝试

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:结果是:

结果

只需sudo pip install packagename

暂无
暂无

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

相关问题 (ChatterBot) 由于 EnvironmentError 无法安装软件包:[Errno 13] 权限被拒绝: - (ChatterBot) Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 由于环境错误无法安装软件包:[Errno 2] - Could not install packages due to an EnvironmentError: [Errno 2] pip 安装过程中出错:由于 EnvironmentError 无法安装软件包:[Errno 13] 权限被拒绝 - Error during pip install: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied 错误:由于环境错误而无法安装软件包:[Errno 13] 权限被拒绝:&#39;/var/project_env/bin/pip&#39; - ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/var/project_env/bin/pip' 由于环境错误,无法安装软件包:[Errno 2] 没有此类文件或目录 - Could not install packages due to an EnvironmentError: [Errno 2] No Such file or directory 由于环境错误无法安装包:[Errno 2] 没有这样的文件或目录 \\METADATA - Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory \\METADATA 错误:由于环境错误,无法安装软件包:[Errno 2] 没有这样的文件或目录: - ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 由于 EnvironmentError 无法安装软件包:[Errno 28] 设备上没有剩余空间 - Could not install packages due to an EnvironmentError: [Errno 28] No space left on device 错误:由于环境错误而无法安装软件包:[Errno 9] 文件描述符错误 - ERROR: Could not install packages due to an EnvironmentError: [Errno 9] Bad file descriptor 由于环境错误而无法安装软件包:[Errno 2]没有这样的文件或目录:… - Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: …
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM