2

I am working on a Python 2.7 program. I am not used to use Spyder, I usually use vanilla Python form the terminal. Since my calculation are quite heavy I would like now to use Spyder just to do the plotting without having to run the whole calculation. Basicly I want to use the Spyder because it keeps the variables in a workspace and because it provides the possibilty of messing around with the plotting without having to run a full calculation every time.

I installed Spyder with

sudo apt install spyder

How should I use this installation to choose whether Python 2.7 or Python 3?


What I tried

I also tried to install Spyder throught pip as suggested here like so

python -m pip install spyder

which is not working. So I forced pip to install a specific version of Spyder with

sudo pip install -Iv spyder==2.3.9

but again there is an issue with dependencies. And even if it had worked, it wouldn't have allowed me to select the version of Python. It would only have installed a version of Spyder that works with Python 2.7.

Changing Python interpreter as suggested here doesn't work either. I tried to specify bin/python as Python interpreted but it doesn't work with the IPython kernel.


Solution

As mentionned below the solution is to use conda and virtual environments for each Python version.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
  • Another option to consider would be a Jupyter Notebook. Just a thought if Spyder is giving you a heacache. The notebook allows you to select the version of Python you want to run. – S3DEV Jan 21 '20 at 11:00
  • Is it possible to export the variables to a file with Jupyter? I believ it's possible with Spyder. That way I can run my calculation once, save the variables to a file and then mess around with Jupyter. –  Jan 21 '20 at 11:25
  • You can `pickle` the variables to store them. You can also export the code to a .py module for later use (in Spyder) if you like. – S3DEV Jan 21 '20 at 11:29
  • Thanks with that I don't really need Spyder. However I am still interested in finding how to choose launch Spyder with Python 2.7 or Python 3. –  Jan 21 '20 at 11:38
  • Regarding launching Spyder, I do as the answer below suggests. Setup a virtual environment (I use `conda`) for 2.7 and one for 3.x. From the terminal, activate the environ and launch Spyder. Works brilliantly. – S3DEV Jan 21 '20 at 11:40

1 Answers1

1

I'm not sure if I got your question right, but if you are not sure how to change the Python interpreter in Spyder, then take a look into this post: How to change python version in anaconda spyder

If you want to run spyder, just type spyder into your terminal. If you want to use multiple versions of python consider to use virtual environments created by virtualenv or conda. For this, take a look into this article: Conda: Creating a virtual environment

Rgds

Max
  • 93
  • 6
  • Do I really need to use `conda` or something else? When I am launching a Python script from the Terminal I use `python filename.py` if I want Python 2.7 or `python3 filename.py` if I want Python 3. I was expected something like that for Spyder. –  Jan 21 '20 at 10:18
  • Spyder is an IDE, a development environment. It can also execute scripts, but its made for writing code and testing it. As I understand you now, you want to have something for just displaying plots? If so and your plots are created from your code, then you cannot avoid launching your code. Except you store your plots as pictures and display these. – Max Jan 21 '20 at 10:36
  • I want to use Spyder to run my calculation once and after be able to execute a just a few lines to plot without having to run again the calculation. Basically I want to use the functionality of keeping the variables and execute just a few line of a code. –  Jan 21 '20 at 10:54