Default Python version

Dear all,

I'm having some issue using the default python version of my Ubuntu Mate 18.04 (2.7.15+) with a program that requires a more modern Unicode support (as far as I understood 2.7.16 would be enough). Can the default python be safely upgraded to that version in Ubuntu Mate? Otherwise, is there a way to launch a program somehow pointing him to python3? The author of this specific software suggested me to launch it using the -R option, that is supposed to autodetect the newer version of python and reset the default, or so he says, but it don't work.

This is the error I get when I try to run a python script from that program:
Error: could not find symbol "PyUnicodeUCS2_FromWideChar"
Python could not be properly initialized. We must quit.

For reference, this is the problem as I have explained in more detail elsewhere, I don't want to bother you with details about a third-party software, but in case you need them: https://www.nitrc.org/forum/forum.php?thread_id=10603&forum_id=6713

Thank you in advance for any answer.

Lorenzo

EDIT: the problem was solved for me with an internal setting of the software, but I would take advantage of the circumstance to understand better the matter: is Mate (or Ubuntu) compatible with a more recent version of Python 2.7 set as default? If not, it would still possible to install Python 3 in a standard path such as /usr/lib? And how does the -R (or -r?) option work? I can't find anything online about it.

Welcome! Both Python 2 and 3 are pre-installed in Ubuntu MATE. In 18.04, those versions are:

$ python --version
Python 2.7.15+

$ python3 --version
Python 3.6.8

Running the right one depends on the "shebang" at the top of the Python file you're trying to run, or the command is used to execute the file.

Python 2:

#!/usr/bin/python
#!/usr/bin/python2
#!/usr/bin/env python
#!/usr/bin/env python2

python /path/to/script

Python 3:

#!/usr/bin/python3
#!/usr/bin/env python3

python3 /path/to/script

In some distributions, python might run Python 3.x, and have python2 instead. Ubuntu has both python2 and python3, with python defaulting to 2.x.


While possible, I wouldn't recommend manually installing a version of Python 2.x or 3.x outside the distribution's repositories, as it can become a pain to maintain multiple versions of Python on the system, the libraries required by programs and can introduce inconsistency issues.

There is a tool called virtualenv that can be used to create isolated environments of Python.

:bulb: Tip - Ubuntu 19.10 that's being released on the 17th of October ships Python 2.7.16.

Thank you very much for your answer. I didn't know of virtualenv, luckily my problem has been solved but it could be of use in the future. It also interesting that Ubuntu 19.10 is released with Python 2.7.16, although I need to stick to LTS version because I some other software that I need is optimized and maintained only for LTSs. But it is good to know that when I'll upgrade to 20.04 I will find it there.

Thanks again.

1 Like