0

I have two versions of python, /usr/bin/python (version 2.7.10 in MacOS ) & /usr/local/bin/python(version 2.7.13 installed via brew).

I use pip (installed by brew install python )to install a module protobuf!

but /usr/bin/python cannot find the module protobuf,whereas the /usr/local/bin/python could find it.

how can I make the /usr/bin/python to find the module

update

@RNB according to the installation, sudo python get-pip.py I have errors like

: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

solution

according to @RNB's advice, first clean all pip packages,uninstall brew python+pip, install pip for sys's python by python get-pip.py, maybe it gives error with wheel, so set options --no-setuptools&--no-wheel for python get-pip.py,install or upgrade setuptools & wheel via pip.At last install protobuf,problem solved!

Roby
  • 145
  • 1
  • 12

2 Answers2

3

Use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip.

python2 -m pip install SomePackage # default Python 2

python2.7.10 -m pip install SomePackage # specifically Python 2.7.10

check this

Best practice is to use virtualenv,

If you want to install a package to a particular location using pip, you can simply do

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

using --target option,

pip install --target=<path> package_name

you also need to add the <path> location to PYTHONPATH

Surajano
  • 2,688
  • 13
  • 25
  • I want to keep OS cleaner! so I want to remove the python installed via brew. I follow the @RNB advice to install pip for system python. but I encounter installation errors! – Roby Apr 26 '17 at 05:29
  • follow this way to remove unwanted python versions : http://stackoverflow.com/a/3819829/4531386 – Surajano Apr 26 '17 at 05:38
0

You will have to install pip for /usr/bin/python and install protobuf via your new pip installation.

RNB
  • 38
  • 6