Spyder: Changing to python2.7 interpreter in Spyder3

Created on 8 Apr 2015  路  11Comments  路  Source: spyder-ide/spyder

I have uninstalled Spyder2 and installed Spyder3. I was told that it would be easy to continue using the python2.7 interpreter in the new Spyder3. I changed the interpreter using Preferences > Console > Advanced settings > Use the following Python interpreter: changing this to /usr/bin/python2.7. It comes up with a warning:

You selected a Python 2 interpreter for the console but Spyder is running on Python 3!.

Although this is possible, we recommend you to install and run Spyder directly with your selected   interpreter, to avoid seeing false warnings and errors due to the incompatible syntax between these two Python versions.

I left the default PYTHONSTARTUP option.

Upon choosing to open a new python console I get the following which is correct:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Upon restarting the IPython console/kernel I get the following message:

An error ocurred while starting the kernel
Traceback (most recent call last):
File "/usr/lib/python3/dist鈥憄ackages/spyderlib/widgets/externalshell/start_ipython_kernel.py", line 186, in 
ipk_temp.config = kernel_config()
File "/usr/lib/python3/dist鈥憄ackages/spyderlib/widgets/externalshell/start_ipython_kernel.py", line 45, in kernel_config
from spyderlib.config import CONF
ImportError: No module named spyderlib.config

When I switch to the Python console and run my script I get the following message:

runfile('blablabla.../RT_param_compare.py',  wdir=r'blablabla...')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'runfile' is not defined

I am not sure what I should do to remedy this.

Most helpful comment

I found this one useful for anaconda:

Try typing these 3 lines from the anaconda command prompt:
conda create -n spyder python=2.7 spyder
conda activate spyder
spyder

All 11 comments

Mixing python versions is not really supported, as you saw yourself. I think there is a misconception here: the last version of spyder is 2.3.4, and this version can run on either python 2 or python 3. So you can still use spyder with python2 and get the last improvements and bug fixes. As far as I can see, reinstalling spyder for python2 is more appropriate for you.

For reference or if you want to keep python3, I guess that a workaround for your last problem is to start a dedicated console interpreter instead of running your file in the current one, but I didn't test it.
I think that the IPython error appears because it tries to load spyderlib.config from python2 while it is installed for python3 only.
I'm not sure whether we should consider these as bugs or disable the functionnality?

I have had a an issue with Spyder2 #2303 and was told it is no longer supported and needed to install Spyder3. I was also told that Spyder3 can run with python 2.7. It seems I am in a catch 22, as my script won't run in Spyder2 and this won't be fixed on your side, and I can't get the script to run under Spyder3 using python 2.7 either. I have been quite fond of using Spyder instead of vim for my editing etc. but it seems I am having to return to my old ways of writing my scripts, or can you advise me how to make it work under Spyder3 without having to revert to python 3? Regarding your suggestion to run a dedicated console with 2.7, I thought that is what I did in my first post, and it came up with the runfile() error.

In #2303 @ccordoba12 told you to use spyder _2.3.4_, not spyder _3_. He also specifically told you that spyder still supports python2 and python3. To keep things simple, you need the python3 version of spyder to run python3 scripts, and the python2 version of spyder to run python2 scripts. But the version number of spyder will still be the same. Please reread carefully #2303 and keep having fun (or working, it depends) with spyder !

As for my suggestion, you have to change a setting in the run options (F6 by default) so that the script runs in its own console. This way I think it doesn't use runfile, but again I didn't test it.

To summarize, the simpler for you is to uninstall spyder, and install spyder v2.3.4 for python2. This way you'll have an up-to-date version with the correct python interpreter.

I agree with @Nodd, this is not an issue. This is caused by your misunderstanding of how things works.

But I think @Nodd is quite clear now :-) So I'm closing this issue.

Thanks for informing me. I thought Spyder 2.3 was commonly known as Spyder3. Apologies. So you learn. I downloaded the spyder version 2.3.4 and installed from source. Works fine now. Thanks.

Just to clarify: are you getting the netcdf errors you reported before in 2.3.4?

It seems to work without requiring the creation of a separate class as in my previous post #2303.

I found this one useful for anaconda:

Try typing these 3 lines from the anaconda command prompt:
conda create -n spyder python=2.7 spyder
conda activate spyder
spyder

Sorry, may be too late.
Did you mean "source activate spyder"?
Or really it's "conda activate spyder"?
Anyway, It's not clear in may case: the IPython looks as running Python 3, and if I run "print 'Hello, World!'", the appears "
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?" (it's Python 3 still)

Looks like definetively have to install Spyder2

Yes sorry it should be
source activate spyder

After activating
Use conda or pip to install other libraries...

The most useful way to work with python 2 and 3 simultaneously, is as follows:
While having spyder3 installed

-Open Anaconda Prompt and type: conda create -n py27 python=2.7 anaconda
-Once the new env was created (py27) type: activate py27
-Then type: spyder
You'll see that the python version is 2.7 now

Was this page helpful?
0 / 5 - 0 ratings