Change Python version a script is referring to

0

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?

bajotupie

Posted 2018-12-25T20:13:46.073

Reputation: 5

Does the command python —version give you Python 2 or 3? If it gives version 3, type alias python=python2 and then run the script. This points python to version 2 instead of 3. – agtoever – 2018-12-25T20:22:56.313

You must have python3 first in $PATH. Try: PATH=/usr/bin:$PATH ./install_esoreflex. – Arkadiusz Drabczyk – 2018-12-25T20:24:45.380

@agtoever it gives Python 3. You mean I have to run alias python=python2 and then ./install_esoreflex in the same terminal? – bajotupie – 2018-12-25T20:43:53.140

Added it as an answer. Please accept it. – agtoever – 2018-12-26T05:52:24.290

Answers

0

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.

agtoever

Posted 2018-12-25T20:13:46.073

Reputation: 5 490

0

See if the script has a "shebang" (first line with #!...) and change the python reference in it to point to python2 instead of just python

Edit:

OK, so the whole script assumes that your default python is Python v2. You can perhaps get an installation run successfully using an alias (alias python=python2) as indicated in comments above.

However, it is likely that the whole package expects python to be python v2, so you will have to do the same each time you run something from the package. But if you set a permanent alias this may conflict with other things in your system that expect python=python3.

So you may have to use facade scripts to launch parts of that package after setting up an alias for python v2.

xenoid

Posted 2018-12-25T20:13:46.073

Reputation: 7 552

The first line is #!/bin/sh. How do I change the python reference? – bajotupie – 2018-12-25T20:45:20.043

Edited the answer... – xenoid – 2018-12-25T21:04:58.633

the script looks the python binary using command-v python, change that line to command -v python2 – user1330614 – 2018-12-26T22:50:21.277

0

this solves your problem in one line without changing system's python symlink which can lead to other problems.

wget ftp://ftp.eso.org/pub/dfs/reflex/install_esoreflex  -O - | sed 's/command -v python/command -v python2/g' | sh

user1330614

Posted 2018-12-25T20:13:46.073

Reputation: 148