Pip问题-由于环境原因无法安装软件包

2024-04-29 20:33:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想我的Mac上的Python和/或pip有一些问题。我已经在全球安装了Python2.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,但是我不想这样做。

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


Tags: installpipandtheenvssh2withsudo
2条回答

您可以使pip在virtualenv库位置内安装包:

sudo -H venv/bin/pip install fabric

出现permission denied错误是因为您已经用sudo安装了虚拟环境。跑步

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

以修复权限。如果您有其他权限问题,甚至可以修复整个home dir的权限:

$ 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之前,需要先安装相应的库:

$ brew install libssh2

相关问题 更多 >