9

From what I have learnt in the documentation it states that you can easily switch between 2 python environments by just creating a new variable using command prompt

"conda create -n python34 python=3.4 anaconda" if i already have python 2.7 installed.

An environment named python 34 is created and we can activate it using "activate python 34" But all this happens like executing the above commands happens in my windows command prompt. I want to switch between python versions in spyder IDE, How to do this?

Prudhvi Charan
  • 115
  • 1
  • 1
  • 11

3 Answers3

9

Spyder is launched from the environment that you're using.

So if you want to use python 3 in Spyder then you activate python34 (or whatever you named the environment with Python 3) then run spyder.

If you want to use python 2 in Spyder then you deactivate the python3 environment (or activate an environment in which you installed Python 2) then run spyder.

I do not believe that you can change environments once Spyder is launched.

N.B. you may need to install Spyder in each environment, depending on your set up, by first activating the environment then using conda install spyder.

nekomatic
  • 5,988
  • 1
  • 20
  • 27
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • Thanks for your answer and It really helped me. What about various python libraries (eg. Numpy,Scipy etc) are these libraries to be installed for both versions of python or if once installed can be used for both python 2 and 3 – Prudhvi Charan Mar 14 '17 at 14:49
  • That's a pleasure! Some are installed by default - you can see what python libraries are installed in the currently active environment by calling `conda list`. – Ari Cooper-Davis Mar 14 '17 at 14:57
  • 1
    and I don't think I need to install spyder for other environment. It automatically gets installed on creating environment using this "conda create -n python34 python=3.4 anaconda" You can see this in the attached picture bottom (2 spyders) https://drive.google.com/open?id=0B02q8l5DVZGdcVRpcW5JWFNNdlU – Prudhvi Charan Mar 14 '17 at 16:45
  • Ah fantastic, I'm glad to hear it. I mentioned that because I had to install spyder again, but I created the python3 environment a long time ago. – Ari Cooper-Davis Mar 14 '17 at 19:12
  • @PrudhviCharan that's because the `anaconda` in your command specifies a standard set of Python packages which includes Spyder. Try leaving it out of the command to see the difference. – nekomatic May 15 '18 at 10:09
  • 1
    Since this question has been cited in order to close another Spyder / conda / Python 2 vs 3 question as a duplicate, I took the liberty of editing this answer to make it a little more general. For example it originally suggested specifying `spyder=3.1.3` but that's no longer the latest version, etc. – nekomatic May 15 '18 at 10:11
2

Just go to preferences in spyder & then go to Python interpreter-> Use the following python interpreter: here, from browse files option, give path for your python2.exe file & then apply. Now your python2 doesn't have spyder-kernels module required to open console in spyder so install it by writing command in cmd python2 -m pip install spyder-kernels. Here python2 -m is used coz I have two versions of python installed

willwrighteng
  • 1,411
  • 11
  • 25
1

Just go to the directory where you have installed Spyder(use cd in command prompt), for me, it looks like "C:\Users\Rohan\Anaconda2" and type spyder in cmd. it will run your Spyder IDE.

Rohan Garg
  • 35
  • 5