Spyder: Use simply 'python3' as custom interpreter

Created on 29 Nov 2017  路  15Comments  路  Source: spyder-ide/spyder

Description of your problem

I want to use the system-installed Spyder3 to work on code that runs unter (several different) virtualenv environments. (I cannot use a pip-installed newer Spyder version because of its Qt dependency.)
For this, I currently have to change Spyder's "Python interpreter" to the absolute path of the virtualenv's python3 executable each time I change the environment.

For faster changes between virtualenv environments (or beween working in a virtualenv or system environment), it would be useful to set the interpreter just to python3, such that it is found on the $PATH.

What steps will reproduce the problem?

  1. Under Preferences -> Python interpreter, try to set the interpreter just to python3.

What is the expected output? What do you see instead?
I would expect that the new setting is accepted.
Instead, a dialog says "You selected an invalid Python interpreter [...]".

Please provide any additional information below
I have got a workaround:
When I close Spyder and manually edit spyder.ini to executable = python3, everything works fine (i.e. !which python correctly shows my virtualenv's python) until I open the Preferences dialog again.

Versions and main components

  • Operating system: Debian Stretch

The following are the system defaults (at the current update level):

  • Spyder Version: 3.1.3
  • Python Version: 3.5.3
  • Qt Version: 5.7.1
  • PyQt Version: 5.7

Dependencies


Please go to the menu entry Help > Optional Dependencies (or
Help > Dependencies), press the button Copy to clipboard
and paste the contents below:
jedi >=0.9.0 : 0.10.0 (OK)
matplotlib >=1.0 : 2.0.0 (OK)
nbconvert >=4.0 : 4.2.0 (OK)
numpy >=1.7 : 1.12.1 (OK)
pandas >=0.13.1 : 0.19.2 (OK)
pep8 >=0.6 : 1.7.0 (OK)
psutil >=0.3 : 5.0.1 (OK)
pyflakes >=0.6.0 : 1.3.0 (OK)
pygments >=2.0 : 2.2.0 (OK)
pylint >=0.25 : 1.7.4 (OK)
qtconsole >=4.2.0: 4.2.1 (OK)
rope >=0.9.4 : 0.10.5 (OK)
sphinx >=0.6.6 : 1.4.9 (OK)
sympy >=0.7.3 : None (NOK)

Help wanted Preferences Enhancement

All 15 comments

I think an easier way to solve this would be to maintain a list of the most recent (10?) used interpreters, so users can easily switch between them.

@jondo, what do you think?

This would only be a slight improvement.

Just having executable = python3 would make it unnecessary to touch the preferences at all. A Spyder launch in an "activated" environment would automatically get the right executable.

Since editing spyder.ini to just python3 works, why not allow this editing to also happen in the GUI?

It would seem that the enhancement suggested by @ccordoba12 , adding is a pop up list of the most recently used python backends, seems to be somewhat different to bug pointed out by @jondo , that the Preferences GUI does not allow them to add the system python3 installation as a valid interpreter, even though it would function fine. The only reason it needs to be changed every session is due to this reason, and would be entirely unnecessary if it were fixed; on the other hand, assuming it wasn't, a less resourceful user wouldn't be able to even add it in the first place as it would fail, and might not get added anyway as it was manually edited into the ini.

Not that it wouldn't be a useful enhancement, but it seems rather secondary to the issue at hand which would appear to be a bug fix of the validity checking of the interpreter field in the preferences GUI, and I would think a simpler and quicker fix, at least to my naive eye.

@jondo, if you have Spyder installed in every environment (as it seems the case), you don't need to change the Python interpreter every time you start Spyder. Simply using the default interpreter should pick up the interpreter in your environment.

No, as I wrote, I need to use the system-installed Spyder 3.1.3. I have tried installing Spyder in the environments, but this gives me an error about missing Qt libraries. I only have the system-installed Qt 5.7.1 available.

Then how do you expect that simply passing python3 would select the interpreter of your environment?

When I apply my workaround of directly editing spyder.ini to executable = python3, I _see_ that this works: I can use the packages that are only installed in my environment. Also, !which python (in Spyder's IPython console) shows the correct path into my environment.

Can you please change this issue's title back? The new one does not reflect my problem.

We do some validations to detect if the executable you pass as a custom interpreter is really a Python interpreter. So that's why we need he full path of the executable.

If you manage to make those validations to work by simply passing python3, then we'll merge your work for sure.

What about internally replacing python3 by whatever is returned from which python3 before doing the validations?

Sounds good, but this is a specific case of yours, so sorry to say it but we don't plan to work on it.

However, as I said, we're welcome to receive PRs that fix it, in multiplatform way (e.g. there's no which on Windows).

I understand. As a note, on Windows the where command might work.

At least on my machine, it indeed returns the exact same results, in the same format, etc., as which does.

I'm having the same issue, how do you edit spyder.ini? Where is the file located?

@SreehariRamMohan ~/.spyder-py3/spyder.ini

I want to avoid global state, so I do not want to edit my Spyder preferences whenever I am switching between venvs. Fortunately, I found a solution:

  • In the Spyder preferences, I keep the Console -> Python executable at Default.
  • I launch Spyder within my venv as
python `which spyder3`

This way, the venv's python is used for Spyder's Python consoles.

(Reading https://github.com/firedrakeproject/firedrake/issues/1218, @ZhouleiJoeStone might also be interested in this.)

Was this page helpful?
0 / 5 - 0 ratings