pytorch

Форк
0
/
diagnose_protobuf.py 
92 строки · 2.9 Кб
1
## @package diagnose_protobuf
2
# Module scripts.diagnose_protobuf
3
"""Diagnoses the current protobuf situation.
4

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
9
machine.
10

11
Usage:
12
    [set your environmental variables like PATH and PYTHONPATH]
13
    python scripts/diagnose_protobuf.py
14
"""
15

16
import os
17
import re
18
from subprocess import PIPE, Popen
19

20

21
# Get python protobuf version.
22
try:
23
    import google.protobuf
24

25
    python_version = google.protobuf.__version__
26
    python_protobuf_installed = True
27
except ImportError:
28
    print("DEBUG: cannot find python protobuf install.")
29
    python_protobuf_installed = False
30

31
if os.name == "nt":
32
    protoc_name = "protoc.exe"
33
else:
34
    protoc_name = "protoc"
35

36
try:
37
    p = Popen([protoc_name, "--version"], stdout=PIPE, stderr=PIPE)
38
    out, err = p.communicate()
39
except:
40
    print("DEBUG: did not find protoc binary.")
41
    print("DEBUG: out: " + out)
42
    print("DEBUG: err: " + err)
43
    native_protobuf_installed = False
44
else:
45
    if p.returncode:
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
50
    else:
51
        tmp = re.search(r"\d\.\d\.\d", out)
52
        if tmp:
53
            native_version = tmp.group(0)
54
            native_protobuf_installed = True
55
        else:
56
            print("DEBUG: cannot parse protoc version string.")
57
            print("DEBUG: out: " + out)
58
            native_protobuf_installed = False
59

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).
63
"""
64

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
68
protobuf via:
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/
73
"""
74

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.
79
"""
80

81
# Now, give actual recommendations
82
if not python_protobuf_installed:
83
    print(PYTHON_PROTOBUF_NOT_INSTALLED)
84

85
if not native_protobuf_installed:
86
    print(NATIVE_PROTOBUF_NOT_INSTALLED)
87

88
if python_protobuf_installed and native_protobuf_installed:
89
    if python_version != native_version:
90
        print(VERSION_MISMATCH)
91
    else:
92
        print("All looks good.")
93

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.