Python Pip 问题 - 由于 EnvironmentError 无法安装软件包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50639973/
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
Pip problems - Could not install packages due to an EnvironmentError
提问by goblin_rocket
I think I have some issues with either Python and/or pip on my Mac. I have Python 2.7 installed globally and then I normally setup virtualenvs and install Python3.6.4 but in the last day or so Ive been getting problems with packages such as Fabric and SSH2 where I have either not been able to install them with various errors or with Fabric it throws when I try to import the package.
我想我的 Mac 上的 Python 和/或 pip 有一些问题。我在全局安装了 Python 2.7,然后我通常设置 virtualenvs 并安装 Python3.6.4,但在最后一天左右,我遇到了诸如 Fabric 和 SSH2 之类的包的问题,我要么无法安装它们,要么出现各种错误,要么使用当我尝试导入包时它会抛出 Fabric。
Im now trying to remove Fabric and install Fabric3 and its throwing errors like this:
我现在试图删除 Fabric 并安装 Fabric3 及其引发的错误,如下所示:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Users/david/Documents/projects/uptimeapp/env/lib/python3.6/site-packages/Fabric3-1.14.post1.dist-info'
Consider using the `--user` option or check the permissions.
(env) Davids-MacBook-Air:uptimeapp david$ pip install fabric3 --user
Can not perform a '--user' install. User site-packages are not visible in this virtualenv.
If I do sudo pip install fabric
then it installs but with this warning:
如果我这样做,sudo pip install fabric
它会安装但带有此警告:
The directory '/Users/david/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/david/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
But I thought it was not advised to pip install with sudo?
但我认为不建议使用 sudo pip install?
These are the errors I get when I try to pip install ssh2-python
这些是我尝试时遇到的错误 pip install ssh2-python
ssh2/agent.c:569:10: fatal error: 'libssh2.h' file not found
#include "libssh2.h"
^~~~~~~~~~~
1 error generated.
error: command 'clang' failed with exit status 1
----------------------------------------
Command "/Users/david/Documents/projects/uptimeapp/env/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/bl/97vt48j97zd2sj05zmt4xst00000gn/T /pip-install-mpyq41q4/ssh2-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/bl/97vt48j97zd2sj05zmt4xst00000gn/T/pip-record-qul_k3kq/install-record.txt --single-version-externally-managed --compile - -install-headers /Users/david/Documents/projects/uptimeapp/env/bin/../include/site/python3.6 /ssh2-python" failed with error code 1 in /private/var/folders/bl/97vt48j97zd2sj05zmt4xst00000gn/T/pip-install-mpyq41q4/ssh2-python/
I have managed to remove Fabric and install Fabric3 with the sudo command but I would rather not do that.
我已经设法删除 Fabric 并使用 sudo 命令安装 Fabric3,但我宁愿不这样做。
I should add that Ive not had any other problems with installing other packages either globally in Python2.7 or in envs.
我应该补充一点,我在 Python2.7 或 envs 中全局安装其他包时没有任何其他问题。
采纳答案by hoefling
The permission denied
error is raised because you've already borked your virtual environment by installing with sudo
. Run
permission denied
引发该错误是因为您已经通过使用sudo
. 跑
$ sudo chown -R david:staff /Users/david/Documents/projects/uptimeapp/env
to fix the permissions. Maybe it's even wise to fix the permissions for the whole home dir, should you have other permission issues:
修复权限。如果您有其他权限问题,修复整个主目录的权限可能更明智:
$ sudo chown -R david:staff /Users/david/
Now reinstalling packages should work again:
现在重新安装软件包应该可以再次工作:
$ source /Users/david/Documents/projects/uptimeapp/env/bin/activate
$ (env) pip uninstall -y fabric
$ (env) pip install fabric
'libssh2.h' file not found
'libssh2.h' file not found
means that before installing ssh-python
, you need to install the according lib first:
意味着在安装之前ssh-python
,您需要先安装相应的lib:
$ brew install libssh2
回答by Hajar Homayouni
You can make pip to install the package within the virtualenv library location:
您可以使用 pip 在 virtualenv 库位置安装包:
sudo -H venv/bin/pip install fabric