我认为我的Mac上的Python和/或pip存在一些问题。我安装了全局的Python 2.7,然后通常设置虚拟环境并安装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/
我已经使用sudo命令成功删除了Fabric并安装了Fabric3,但我宁愿不这样做。
值得一提的是,我在Python2.7中全局安装其他软件包或envs中也没有遇到任何其他问题。
libssh2
的公式,我发现有一个测试明确检查所需的头文件是否已安装。因此该文件必须在/usr/Cellar/
中的某个位置:运行brew list libssh2 | grep
libssh2.h` 来检查。 - hoeflingclang
,这表明 Homebrew 存在一些问题。也许brew doctor
命令会提供一些有用的信息。 - hoeflingCPPFLAGS="-I/path/to/libssh2.h/parent/dir" CFLAGS="-I/path/to/libssh2.h/parent/dir" pip install ssh2-python
,但是,一个正确的解决方案应该是在您的环境中修复默认的包含路径。 - hoefling