【问题标题】:How to make system python to find modules installed via pip? [duplicate]如何让系统 python 找到通过 pip 安装的模块? [复制]
【发布时间】:2017-09-23 07:41:45
【问题描述】:

我有两个版本的 python,/usr/bin/python(MacOS 中的版本 2.7.10)和/usr/local/bin/python(通过brew 安装的版本 2.7.13)。

我使用pip(由brew install python安装)安装一个模块protobuf

但是/usr/bin/python 找不到模块protobuf,而/usr/local/bin/python 可以找到它。

如何让/usr/bin/python 找到模块

更新

@RNB 根据安装,sudo python get-pip.py我有类似的错误

:Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 640kB/s 
Collecting wheel
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 6.3MB/s 
Installing collected packages: pip, wheel
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
  Rolling back uninstall of pip
Exception:
Traceback (most recent call last):
  File "/tmp/tmpW2v8kJ/pip.zip/pip/basecommand.py", line 215, in main
  .....
    File"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 235, in _compile
    cachekey = (type(key[0]),) + key
RuntimeError: maximum recursion depth exceeded while calling a Python object

解决方案

根据@RNB的建议,首先清理所有pip包,卸载brew python+pip,通过python get-pip.py为sys的python安装pip,可能wheel出错,所以设置选项--no-setuptools &--no-wheel for python get-pip.py,安装或升级setuptools & wheel via pip。最后安装protobuf,问题解决了!

【问题讨论】:

    标签: python pip


    【解决方案1】:

    结合使用版本控制的 Python 命令和 -m 开关来运行适当的 pip 副本。

    python2 -m pip install SomePackage # 默认 Python 2

    python2.7.10 -m pip install SomePackage # 特别是 Python 2.7.10

    check this

    最佳做法是使用virtualenv

    如果您想使用 pip 将软件包安装到特定位置, 你可以简单地做

    pip install --install-option="--prefix=$PREFIX_PATH" package_name

    使用 --target 选项,

    pip install --target=<path> package_name

    您还需要将<path> 位置添加到PYTHONPATH

    【讨论】:

    • 我想让操作系统更干净!所以我想删除通过brew安装的python。我按照@RNB 的建议为系统 python 安装 pip。但是我遇到安装错误!
    • 按照这种方式删除不需要的python版本:stackoverflow.com/a/3819829/4531386
    【解决方案2】:

    您必须为/usr/bin/python 使用install pip 并通过您的新pip 安装安装protobuf

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2020-03-03
      • 2016-01-09
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      相关资源
      最近更新 更多