【python】pip安装失败问题

在mac中安装python依赖包gevent出现各种异常,mark一下解决过程

依赖包安装

pip install gevent

出现以下错误

 ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-install-m9tv6pok/greenlet/setup.py'"'"'; __file__='"'"'/private/var/folders/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-install-m9tv6pok/greenlet/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-install-m9tv6pok/greenlet/pip-egg-info
         cwd: /private/var/folders/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-install-m9tv6pok/greenlet/
    Complete output (6 lines):
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: setup.py --help [cmd1 cmd2 ...]
       or: setup.py --help-commands
       or: setup.py cmd --help
    
    error: invalid command 'egg_info'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

setuptools 版本

还有根据提示,或许setuptools 版本太旧,所以出现以下问题python setup.py egg_info Check the logs for full command output
升级setuptools

pip install --upgrade setuptools

升级后报异常

 Running setup.py install for greenlet ... error
    Complete output from command /Users/lluozh/work/git/swqa/venv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-install-x_14v628/greenlet/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/_h/hlpk5_dd2_355l4hvkcjx19m0000gn/T/pip-record-pys1nu76/install-record.txt --single-version-externally-managed --compile --install-headers /Users/lluozh/work/git/swqa/venv/include/site/python3.7/greenlet:
    running install
    running build
    running build_ext
    building 'greenlet' extension
    creating build
    creating build/temp.macosx-10.6-intel-3.7
    gcc -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch i386 -arch x86_64 -g -I/Users/lluozh/work/git/swqa/venv/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c greenlet.c -o build/temp.macosx-10.6-intel-3.7/greenlet.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1

依赖包安装

根据提示,安装gcc依赖包

pip install gcc

安装完成后,再继续安装还是报同样的错

可能是某个功能模块缺失,根据错误提示安装一些依赖的包

pip install xcrun

未能安装成功

pip模块验证

是否pip安装模块出现异常?

pip install flask

可以正常安装,那很可能是因为安装gevent包所依赖的某些模块缺失导致了安装失败

安装whl包

pip可以通过直接安装whl包从方式,步骤如下:

  1. 打开 https://www.lfd.uci.edu/~gohlke/pythonlibs网站,

  2. 搜索需要安装的库的名称gevent
    【python】pip安装失败问题_第1张图片

  3. 找到对应自己系统的版本并下载

  • cp后面的数字时python的版本,如cp36代表python3.6版本
  • WIN后面的数字32/64表示32或者64位系统
  1. 使用pip install +路径文件名安装
pip install c:\gevent-1.4.0-cp37-cp37m-win_amd64.whl

尴尬的是,提示无法支持该包的安装

xcrun依赖

通过错误信息xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun 发现需要在终端安装特定的包

xcode-select --install

输入命令后提示
【python】pip安装失败问题_第2张图片
点击安装,安装一段时间后可安装成功

安装成功

这时再安装gevent,可安装成功

Defaulting to user installation because normal site-packages is not writeable
Collecting gevent
Using cached gevent-20.4.0-cp37-cp37m-macosx_10_9_x86_64.whl (1.8 MB)
Collecting greenlet>=0.4.14; platform_python_implementation == “CPython”
Using cached greenlet-0.4.15.tar.gz (59 kB)
Installing collected packages: greenlet, gevent
Running setup.py install for greenlet … done
Successfully installed gevent-20.4.0 greenlet-0.4.15

你可能感兴趣的:(#,python)