Pip问题 - 由于EnvironmentError导致无法安装软件包

gob*_*ket 11 python macos pip python-3.x

我想我的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.
Run Code Online (Sandbox Code Playgroud)

如果我这样做,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.
Run Code Online (Sandbox Code Playgroud)

但我认为不建议用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/
Run Code Online (Sandbox Code Playgroud)

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

我应该补充一点,我在Python2.7或envs中全局安装其他软件包没有任何其他问题.

hoe*_*ing 10

permission denied引发错误,因为你已经通过安装borked虚拟环境sudo.跑

$ sudo chown -R david:staff /Users/david/Documents/projects/uptimeapp/env
Run Code Online (Sandbox Code Playgroud)

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

$ sudo chown -R david:staff /Users/david/
Run Code Online (Sandbox Code Playgroud)

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

$ source /Users/david/Documents/projects/uptimeapp/env/bin/activate
$ (env) pip uninstall -y fabric
$ (env) pip install fabric
Run Code Online (Sandbox Code Playgroud)

'libssh2.h' file not found

意味着在安装之前ssh-python,您需要先安装相应的lib:

$ brew install libssh2
Run Code Online (Sandbox Code Playgroud)