Python Script – How to Change Python Version a Script is Referring To

bashpythonpython3scriptubuntu 18.04

I have downloaded the script "install_esoreflex" (ftp://ftp.eso.org/pub/dfs/reflex/install_esoreflex) and then execute the following commands:

chmod u+x install_esoreflex

./install_esoreflex 

I get the following warnings

WARNING: The following Python version is installed in your system Python 3.7.0
WARNING: Some of the available workflows use functionality
WARNING: only available in version Python 2.6.0 or greater
WARNING: and will not work properly with the installed version.
WARNING: Additionally, python 3.x is not yet supported.

Eventhough I have both Python 3.7.0 and 2.7. Python 2 is installed in /usr/bin/python2 and Python 3 is installed in /home/USER/miniconda3/bin/python3.
How can I make the script "know" I have python 2?

Best Answer

From Ubuntu version 18.04, python 3 is the default python version (link). This means that /usr/bin/python is symlinked to /usr/bin/python3. You can check this by running python —version.

To default to python 2 in scripts (as your install script requires), you need to install the python 2 version (apt-get install python2). And tell Ubuntu to use that python version.

It is not recommended to change the /usr/bin/python symlink, because it is part of the distribution maintained configuration. Instead you should use the alias command (link): alias python=python2. This (locally) points python to python2, which is found in /usr/bin. You could use this command once in the terminal before running your install script. To change it more permanently, add it to your .bash_profile.

Related Question