3
"""Diagnoses the current protobuf situation.
5
Protocol buffer needs to be properly installed for Caffe2 to work, and
6
sometimes it is rather tricky. Specifically, we will need to have a
7
consistent version between C++ and python simultaneously. This is a
8
convenience script for one to quickly check if this is so on one's local
12
[set your environmental variables like PATH and PYTHONPATH]
13
python scripts/diagnose_protobuf.py
18
from subprocess import PIPE, Popen
23
import google.protobuf
25
python_version = google.protobuf.__version__
26
python_protobuf_installed = True
28
print("DEBUG: cannot find python protobuf install.")
29
python_protobuf_installed = False
32
protoc_name = "protoc.exe"
34
protoc_name = "protoc"
37
p = Popen([protoc_name, "--version"], stdout=PIPE, stderr=PIPE)
38
out, err = p.communicate()
40
print("DEBUG: did not find protoc binary.")
41
print("DEBUG: out: " + out)
42
print("DEBUG: err: " + err)
43
native_protobuf_installed = False
46
print("DEBUG: protoc returned a non-zero return code.")
47
print("DEBUG: out: " + out)
48
print("DEBUG: err: " + err)
49
native_protobuf_installed = False
51
tmp = re.search(r"\d\.\d\.\d", out)
53
native_version = tmp.group(0)
54
native_protobuf_installed = True
56
print("DEBUG: cannot parse protoc version string.")
57
print("DEBUG: out: " + out)
58
native_protobuf_installed = False
60
PYTHON_PROTOBUF_NOT_INSTALLED = """
61
You have not installed python protobuf. Protobuf is needed to run caffe2. You
62
can install protobuf via pip or conda (if you are using anaconda python).
65
NATIVE_PROTOBUF_NOT_INSTALLED = """
66
You have not installed the protoc binary. Protoc is needed to compile Caffe2
67
protobuf source files. Depending on the platform you are on, you can install
69
(1) Mac: using homebrew and do brew install protobuf.
70
(2) Linux: use apt and do apt-get install libprotobuf-dev
71
(3) Windows: install from source, or from the releases here:
72
https://github.com/google/protobuf/releases/
75
VERSION_MISMATCH = f"""
76
Your python protobuf is of version {python_version} but your native protoc version is of
77
version {native_version}. This will cause the installation to produce incompatible
78
protobuf files. This is bad in general - consider installing the same version.
82
if not python_protobuf_installed:
83
print(PYTHON_PROTOBUF_NOT_INSTALLED)
85
if not native_protobuf_installed:
86
print(NATIVE_PROTOBUF_NOT_INSTALLED)
88
if python_protobuf_installed and native_protobuf_installed:
89
if python_version != native_version:
90
print(VERSION_MISMATCH)
92
print("All looks good.")