Repository: spyder-ide/spyder

Issue:
'Execute in external system terminal' unwantedly uses python2 on ubuntu16.04
## Description of your problem

**What steps will reproduce the problem?**

The simple script

    import sys
    print(sys.version)


**What is the expected output? What do you see instead?**

It produces different results, depending on run-configuration
option 1 "Execute in current console" and 2 "... dedicated console" results in output `3.5.2`
case 3 "Excecute in external system terminal" results in output `2.17.12`


**Please provide any additional information below**

I think the problem might be related to this line
https://github.com/spyder-ide/spyder/blob/master/spyder/utils/programs.py#L268

    p_args = ['python']

My suggestion instead:

    if PY2:
        p_args = ['python2']
     else:
        p_args = ['python3']

Note that `python` runs python2 by default on Ubuntu16.04 and Debian9 (and I suppose at least the earlier versions)

## Versions and main components

* Spyder Version: 3.2.2
* Python Version: 3.5.2
* Qt Version: 4.8.7
* PyQt Version: 4.11.4
* Operating system: Ubuntu 16.04.


## Dependencies

IPython >=4.0    :  6.1.0 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.11.0 (OK)
pandas >=0.13.1  :  0.17.1 (OK)
psutil >=0.3     :  5.3.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.7.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
sympy >=0.7.3    :  0.7.6.1 (OK)


'Execute in external system terminal' unwantedly uses python2 on ubuntu16.04
## Description of your problem

**What steps will reproduce the problem?**

The simple script

    import sys
    print(sys.version)


**What is the expected output? What do you see instead?**

It produces different results, depending on run-configuration
option 1 "Execute in current console" and 2 "... dedicated console" results in output `3.5.2`
case 3 "Excecute in external system terminal" results in output `2.17.12`


**Please provide any additional information below**

I think the problem might be related to this line
https://github.com/spyder-ide/spyder/blob/master/spyder/utils/programs.py#L268

    p_args = ['python']

My suggestion instead:

    if PY2:
        p_args = ['python2']
     else:
        p_args = ['python3']

Note that `python` runs python2 by default on Ubuntu16.04 and Debian9 (and I suppose at least the earlier versions)

## Versions and main components

* Spyder Version: 3.2.2
* Python Version: 3.5.2
* Qt Version: 4.8.7
* PyQt Version: 4.11.4
* Operating system: Ubuntu 16.04.


## Dependencies

IPython >=4.0    :  6.1.0 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.11.0 (OK)
pandas >=0.13.1  :  0.17.1 (OK)
psutil >=0.3     :  5.3.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.7.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
sympy >=0.7.3    :  0.7.6.1 (OK)


'Execute in external system terminal' unwantedly uses python2 on ubuntu16.04
## Description of your problem

**What steps will reproduce the problem?**

The simple script

    import sys
    print(sys.version)


**What is the expected output? What do you see instead?**

It produces different results, depending on run-configuration
option 1 "Execute in current console" and 2 "... dedicated console" results in output `3.5.2`
case 3 "Excecute in external system terminal" results in output `2.17.12`


**Please provide any additional information below**

I think the problem might be related to this line
https://github.com/spyder-ide/spyder/blob/master/spyder/utils/programs.py#L268

    p_args = ['python']

My suggestion instead:

    if PY2:
        p_args = ['python2']
     else:
        p_args = ['python3']

Note that `python` runs python2 by default on Ubuntu16.04 and Debian9 (and I suppose at least the earlier versions)

## Versions and main components

* Spyder Version: 3.2.2
* Python Version: 3.5.2
* Qt Version: 4.8.7
* PyQt Version: 4.11.4
* Operating system: Ubuntu 16.04.


## Dependencies

IPython >=4.0    :  6.1.0 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.10.2 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.11.0 (OK)
pandas >=0.13.1  :  0.17.1 (OK)
psutil >=0.3     :  5.3.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.7.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.3 (OK)
sympy >=0.7.3    :  0.7.6.1 (OK)




Discussion:
> My suggestion instead:

```
if PY2:
    p_args = ['python2']
else:
    p_args = ['python3']
```

Your suggestion is the right one, but it should be applied only to Linux.

If you want to see this in our next release, please open a pull request with your suggestion against the `3.x` branch. Else, it's going to take us some time to fix this because it's low priority.
Alternatively, we could use `get_python_executable()` from https://github.com/spyder-ide/spyder/blob/master/spyder/utils/misc.py#L173 , which (I think) uses the same executable that Spyder is run with.
Yep, that's a better suggestion. Thanks @jitseniesen!
> My suggestion instead:

```
if PY2:
    p_args = ['python2']
else:
    p_args = ['python3']
```

Your suggestion is the right one, but it should be applied only to Linux.

If you want to see this in our next release, please open a pull request with your suggestion against the `3.x` branch. Else, it's going to take us some time to fix this because it's low priority.
Alternatively, we could use `get_python_executable()` from https://github.com/spyder-ide/spyder/blob/master/spyder/utils/misc.py#L173 , which (I think) uses the same executable that Spyder is run with.
Yep, that's a better suggestion. Thanks @jitseniesen!
> My suggestion instead:

```
if PY2:
    p_args = ['python2']
else:
    p_args = ['python3']
```

Your suggestion is the right one, but it should be applied only to Linux.

If you want to see this in our next release, please open a pull request with your suggestion against the `3.x` branch. Else, it's going to take us some time to fix this because it's low priority.
Alternatively, we could use `get_python_executable()` from https://github.com/spyder-ide/spyder/blob/master/spyder/utils/misc.py#L173 , which (I think) uses the same executable that Spyder is run with.
Yep, that's a better suggestion. Thanks @jitseniesen!

Resolving patch:
diff --git a/spyder/utils/programs.py b/spyder/utils/programs.py
--- a/spyder/utils/programs.py
+++ b/spyder/utils/programs.py
@@ -21,6 +21,7 @@
 
 # Local imports
 from spyder.utils import encoding
+from spyder.utils.misc import get_python_executable
 from spyder.py3compat import PY2, is_text_string, to_text_string
 
 
@@ -265,7 +266,7 @@ def run_python_script_in_terminal(fname, wdir, args, interact,
         fname = '"' + fname + '"'
         wdir = wdir.replace('/', '\\')
     
-    p_args = ['python']
+    p_args = [get_python_executable()]
     p_args += get_python_args(fname, python_args, interact, debug, args)
     
     if os.name == 'nt':


Test patch: