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 Ubuntu 14.04 package is named python-sklearn (formerly python-scikits-learn) and can be installed in Ubuntu 14.04-19.04 using the following command:
The python-sklearn package is in the default repositories in Ubuntu 14.04 as well as in other currently supported Ubuntu releases.
In Ubuntu 16.04 and later the Python 3 version of python-sklearn can be installed from the default Ubuntu repositories with the following command: