gpt4 book ai didi

python - Pip 问题 - 由于 EnvironmentError 无法安装包

转载 作者:太空狗 更新时间:2023-10-29 18:04:20 27 4
gpt4 key购买 nike

我想我在 Mac 上使用 Python 和/或 pip 时遇到了一些问题。我在全局范围内安装了 Python 2.7,然后我通常设置 virtualenvs 并安装 Python3.6.4,但在最后一天左右,我遇到了 Fabric 和 SSH2 等软件包的问题,​​我无法安装它们并出现各种错误或当我尝试导入包时它会抛出 Fabric。

我现在正在尝试删除 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.

如果我执行 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.

但我认为不建议使用 sudo 进行 pip 安装?

这些是我尝试 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/

我已经设法删除 Fabric 并使用 sudo 命令安装 Fabric3,但我宁愿不这样做。

我应该补充一 pip ,我在 Python2.7 或 envs 中全局安装其他包时没有遇到任何其他问题。

最佳答案

出现 permission denied 错误是因为您已经通过使用 sudo 安装虚拟环境。运行

$ sudo chown -R david:staff /Users/david/Documents/projects/uptimeapp/env

修复权限。如果您有其他权限问题,也许修复整个主目录的权限甚至是明智的:

$ sudo chown -R david:staff /Users/david/

现在重新安装包应该可以再次工作了:

$ source /Users/david/Documents/projects/uptimeapp/env/bin/activate
$ (env) pip uninstall -y fabric
$ (env) pip install fabric

'libssh2.h' file not found

表示在安装ssh-python之前,需要先安装相应的lib:

$ brew install libssh2

关于python - Pip 问题 - 由于 EnvironmentError 无法安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50639973/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com