In addition to standard library and 3rd-party modules Python also has builtin modules. These are written in C and are linked directly in the Python executable. You can find out what these are like this:
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.builtin_module_names
('__builtin__', '__main__', '_ast', '_bisect', '_codecs', '_collections', '_functools', '_heapq', '_io', '_locale', '_md5', '_random', '_sha', '_sha256', '_sha512', '_socket', '_sre', '_struct', '_symtable', '_warnings', '_weakref', 'array', 'binascii', 'cPickle', 'cStringIO', 'cmath', 'errno', 'exceptions', 'fcntl', 'gc', 'grp', 'imp', 'itertools', 'marshal', 'math', 'operator', 'posix', 'pwd', 'select', 'signal', 'spwd', 'strop', 'sys', 'syslog', 'thread', 'time', 'unicodedata', 'xxsubtype', 'zipimport', 'zlib')
virtualenv env
works by copying /usr/bin/python2.7
into env/bin/python
, and then symlinking all the standard library modules into env/lib/python2.7/*.py
.
When you upgrade your system Python, you automatically get the updated standard library in all your virtualenvs (because symlinks!), but you're still using the old copy of the Python executable. This means you're also using the old versions of the builtin modules.
Some standard library modules depend on builtin modules. And sometimes Python 2.7.(x+1) standard library depends on builtin modules that got introduced in Python 2.7.(x+1) too. By using an old virtualenv you're in effect trying to use Python 2.7.x with the standard library of Python 2.7.(x+1), and sometimes this breaks.
Re-creating the virtualenv is the correct solution.
(It's probably sufficient to replace the bin/python
and bin/python2.7
executables inside the virtualenv, assuming that no new stdlib files appeared in the updated system Python.)
Best Answer
The protobuf library and protoc are 2 different things completely.
protoc (called "protobuf-compiler" by apt-get) is an executable that takes .proto files and generates code in the chosen language.
Meanwhile, a protobuf library, like most libraries, contains code for you to reference in your own code - or in this case, code that is referenced by the generated code that protoc outputs.
The protobuf library for python (called "python-protobuf" by apt-get) can be easily updated to v3+ using this command:
I know of no better way to check the version of your protobuf library for python than this:
protoc, on the other hand, is significantly harder to update to v3+. Luckily, you basically only need to update it if you want to use v3 syntax in your .proto definitions.
If you decide to, you should only ever update protoc by downloading source code or binaries from https://github.com/google/protobuf as described in their README.