Python 由于环境错误,无法安装软件包:[Errno 13]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52949531/
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
Could not install packages due to an EnvironmentError: [Errno 13]
提问by Adler
In my MacOS Mojave terminal I wanted to install a python package with pip. At the end it says:
在我的 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.
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。
回答by Gonzalo Garcia
If you want to use python3+to install the packages you need to use pip3 install packageName
如果要使用python3+安装需要用到的包pip3 install packageName
And to solve the errno 13you have to add --user
at the end
为了解决errno 13你必须--user
在最后添加
pip3 install packageName --user
EDIT:
编辑:
For any project in python it's highly recommendedto 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 中的任何项目,强烈建议在Virtualenvironment上工作,这是一种工具,通过为它们创建隔离的 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 activatingit:
然后您只需激活它即可处理它:
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
回答by Dominique Paul
Regarding the permissions command, try using sudo in front of your terminal command:
关于权限命令,请尝试在终端命令前使用 sudo:
sudo pip install --upgrade pip
Sudo is a program that allows you to run the command with the privileges of the superuser.
Sudo 是一个程序,它允许您以超级用户的权限运行命令。
Regarding the python Try running pip as an executable like this:
关于 python 尝试将 pip 作为可执行文件运行,如下所示:
python3.6 -m pip install <package>
回答by sherminator35
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.
当我尝试安装一个包(flask-classful)时,我遇到了同样的错误。
我犯了以 root 身份安装 anaconda 的错误。我更改了已安装 anaconda 文件夹的所有权,并且可以成功安装该软件包。
Use the command chown
with option -R
to recursively change ownership of the installed anaconda folder like so:
使用chown
带有选项的命令-R
递归更改已安装 anaconda 文件夹的所有权,如下所示:
chown -R owner:group /path/to/anaconda
chown -R owner:group /path/to/anaconda
Here owner is your username and group is the group name.
这里 owner 是你的用户名,group 是组名。
回答by Sheetala Prasad Tiwari
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
我犯了同样的错误,然后我意识到我已经以 root 用户身份创建了我的虚拟环境。它被写保护,所以请检查您的虚拟环境是否被写保护。制作一个新的 venv 并重试
回答by Eric Leschinski
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.
答案在错误消息中。过去,您或某个进程执行了以下操作sudo pip
,导致其下的某些目录/Library/Python/2.7/site-packages/...
具有权限,从而使您的当前用户无法访问它。
Then you did a pip install whatever
which relies on the other thing.
然后你做了一个pip install whatever
依赖于另一件事的。
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.
因此,要修复它,请访问 /Library/Python/2.7/site-packages/... 并找到具有 root 或非您用户权限的目录,然后删除然后重新安装这些包,或者只是将所有权强制给用户谁应该有权访问。
回答by Genius
I had the same problem while installing numpy
with pip install numpy
.
我在安装numpy
时遇到了同样的问题pip install numpy
。
Then I tried
然后我试过了
sudo -H pip3 install --upgrade pip
sudo -H pip3 install --upgrade pip
sudo -H pip3 install numpy
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.
说明:该-H
带(HOME)选项sudo
设置HOME环境变量设置为目标用户(root默认情况下)的主目录。默认情况下,sudo 不会修改 HOME。
回答by RohitKumar
MAC & Unix
MAC & Unix
Just by adding sudo to command will work.
只需在命令中添加 sudo 即可。
sudo pip install --upgrade pip
sudo pip install --upgrade pip
回答by nrmzmh
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
我尝试通过以管理员身份运行来打开命令提示符
回答by karthi190
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
蟒蛇 3.7.3
python2.7 --version
gives me
给我
Python 2.7.10
蟒蛇 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.
由于环境错误,无法安装软件包:[Errno 13] 权限被拒绝:'/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. You should consider upgrading via the 'pip install --upgrade pip' command.
收集 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 可用。您应该考虑通过“pip install --upgrade pip”命令进行升级。
回答by Lisa B.
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)