pytorch  1.8.2
About: PyTorch provides Tensor computation (like NumPy) with strong GPU acceleration and Deep Neural Networks (in Python) built on a tape-based autograd system. LTS (Long Term Support) release.
  Fossies Dox: pytorch-1.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

diagnose_protobuf.py
Go to the documentation of this file.
1## @package diagnose_protobuf
2# Module scripts.diagnose_protobuf
3"""Diagnoses the current protobuf situation.
4
5Protocol buffer needs to be properly installed for Caffe2 to work, and
6sometimes it is rather tricky. Specifically, we will need to have a
7consistent version between C++ and python simultaneously. This is a
8convenience script for one to quickly check if this is so on one's local
9machine.
10
11Usage:
12 [set your environmental variables like PATH and PYTHONPATH]
13 python scripts/diagnose_protobuf.py
14"""
15
16import os
17import re
18from subprocess import Popen, PIPE
19
20# Get python protobuf version.
21try:
22 import google.protobuf
23 python_version = google.protobuf.__version__
24 python_protobuf_installed = True
25except ImportError:
26 print("DEBUG: cannot find python protobuf install.")
27 python_protobuf_installed = False
28
29if os.name == 'nt':
30 protoc_name = 'protoc.exe'
31else:
32 protoc_name = 'protoc'
33
34try:
35 p = Popen([protoc_name, '--version'], stdout=PIPE, stderr=PIPE)
36 out, err = p.communicate()
37except:
38 print('DEBUG: did not find protoc binary.')
39 print('DEBUG: out: ' + out)
40 print('DEBUG: err: ' + err)
41 native_protobuf_installed = False
42else:
43 if p.returncode:
44 print('DEBUG: protoc returned a non-zero return code.')
45 print('DEBUG: out: ' + out)
46 print('DEBUG: err: ' + err)
47 native_protobuf_installed = False
48 else:
49 tmp = re.search(r'\d\.\d\.\d', out)
50 if tmp:
51 native_version = tmp.group(0)
52 native_protobuf_installed = True
53 else:
54 print('DEBUG: cannot parse protoc version string.')
55 print('DEBUG: out: ' + out)
56 native_protobuf_installed = False
57
58PYTHON_PROTOBUF_NOT_INSTALLED = """
59You have not installed python protobuf. Protobuf is needed to run caffe2. You
60can install protobuf via pip or conda (if you are using anaconda python).
61"""
62
63NATIVE_PROTOBUF_NOT_INSTALLED = """
64You have not installed the protoc binary. Protoc is needed to compile Caffe2
65protobuf source files. Depending on the platform you are on, you can install
66protobuf via:
67 (1) Mac: using homebrew and do brew install protobuf.
68 (2) Linux: use apt and do apt-get install libprotobuf-dev
69 (3) Windows: install from source, or from the releases here:
70 https://github.com/google/protobuf/releases/
71"""
72
73VERSION_MISMATCH = """
74Your python protobuf is of version {py_ver} but your native protoc version is of
75version {native_ver}. This will cause the installation to produce incompatible
76protobuf files. This is bad in general - consider installing the same version.
77""".format(py_ver=python_version, native_ver=native_version)
78
79# Now, give actual recommendations
80if not python_protobuf_installed:
81 print(PYTHON_PROTOBUF_NOT_INSTALLED)
82
83if not native_protobuf_installed:
84 print(NATIVE_PROTOBUF_NOT_INSTALLED)
85
86if python_protobuf_installed and native_protobuf_installed:
87 if python_version != native_version:
88 print(VERSION_MISMATCH)
89 else:
90 print('All looks good.')
91
92
93
94
std::ostream & print(std::ostream &stream, const Tensor &tensor_, int64_t linesize)
Definition: Formatting.cpp:230