How to run Spyder with anaconda on macOS

Pallawi
5 min readAug 31, 2021
Image source

Introduction

The scope of this blog is to help the reader run Spyder with an anaconda environment on macOS in 5 minutes.

Please follow the below steps sequentially and you will be ready to code and debug your project in Spyder.

What is Spyder?

Spyder is a free and open-source scientific environment written in Python, for Python, and designed by and for scientists, engineers and data analysts.

It features a unique combination of the advanced editing, analysis, debugging, and profiling functionality of a comprehensive development tool with the data exploration, interactive execution, deep inspection, and beautiful visualization capabilities of a scientific package.

Steps to run Spyder with anaconda in 5 minutes

Run the below command to create a fresh conda environment

The name of conda environment is — spyder-env

conda create -n spyder-env
Screenshot of how your terminal would look like after running the above command

Run the below command to activate the new conda environment.

conda activate spyder-env
Screenshot after running the above command
conda install spyder

Run the above command to install spyder

Screenshot of how your screen would look after running the above command
conda install pip
conda update -n base -c defaults conda
conda install spyder-kernels
pip install numpy

After installing all of the above libraries in the anaconda environment - “spyder-env”.

We need to check the anaconda python interpreter path for spyder-env so that we can activate it in the Spyder IDE. Run the below command.

which python 
Please go to this path on your machine and explore the python versions
I have multiple versions of python so I will choose python3.9, you can use the one you have on your machine.
Please follow the three steps mentioned in the above image sequentially
Please follow the four steps mentioned in the above image sequentially

Click on the consoles and “Restart Kernel” . The Restart Kernel will help you to switch to the new anaconda environment.

Restart Kernel

In the console window type the below commands to verify if you are working in the (spyder-env) anaconda environment.

import os
print (os.environ['CONDA_DEFAULT_ENV'])
You can see python 3.9.6 active in the green box and also above two commands in the console window gives the output as spyder-env.

This is how you can include any anaconda or virtual environments in Spyder quickly.

How to open an existing project in Spyder?

under the projects tab, click on the New Project tab
Select the existing directory radio button and location of your project folder
You can now explore your project

How to run your first python script on Spyder?

Unlike any other IDE the command “python filename.py” will not run the file in Spyder.

You need to type the command “run filename.py” to run your python scripts.

Shortcut keys for commenting out lines of Python code in Spyder

  • Single line comment — Command + 1
  • Multi-line comment select the lines to be commented — Command + 4
  • Unblock Multi-line comment — Command + 5

How to change the theme of Spyder from dark to bright

Follow the below steps, click in sequence:

Spyder — — — — -> Preferences — — — ->Appearence

Make sure to choose the combination mentioned in the above image to change the background color or theme of Spyder.

Enjoy coding!

Conclusion:

The scope of this blog is to document steps one can follow to get started with the IDE Spyder with anaconda. Also, I do not want to invest time in the future setting this up on a machine thus a short blog.

Switching IDE’s is time taking and if this is the demand of a new project consider this as an opportunity to learn something new. It took me 2 hours to get this started as there are multiple ways of doing the same thing and one must find the simplest and sustainable way and also the one that is intuitive when it comes to GUI.

Wrote a short blog to stay motivated and not go back to coding in the terminal, Wish me luck with this IDE.

If you find this blog helpful please give a clap, share it with the team who might need this basic yet important blog.

Feel free to subscribe to my page for more Data Science related blogs.

References:

https://fangohr.github.io/blog/spyder-the-python-ide.html

--

--

Pallawi

Computer Vision contributor. Lead Data Scientist @https://www.here.com/ Love Data Science.