The Anaconda Python Distribution 2021-11 Windows 11 Install

In this guide I have a look at installing the Anaconda Python Distribution which contains Python and the most commonly used Data Science Libraries Distribution on Windows 11. Instructions should be equally applicable to a modern build of Windows 10. I go through the installation in some detail, highlighting the installation and adding conda to the path in the Windows Terminal. I then look at use of the conda package manager syntax as well as a reference to physical file locations. I look at using the Anaconda Navigator, Spyder IDE, JupyterLab IDE and Visual Studio Code IDE. I also discuss the difference between the official conda channel and the community conda-forge channel and go through instructions for installing the latest community version of Spyder and JupyterLab using conda environments.

This guide is also equally applicable to Miniconda. Miniconda is a stripped more lightweight version of Anaconda. It is essentially the same installation as Anaconda but gives a more or less empty conda base environment. The Anaconda Individual Edition is designed for only Individual use and has Commercial restrictions, while Miniconda is exempt from these Commercial restrictions. As the (base) conda environment is empty in Miniconda, you will need to create your own conda environments to install the Spyder 5 and JupyterLab 3 IDEs respectively. These steps are covered in this guide.

I have a separate installation guide for Ubuntu 22.04 LTS here:

Table of contents

  1. Uninstalling and Purging an Old Anaconda Installation
    1. Uninstalling
      1. Purging Old Configuration Files
        1. Old Start Menu Shortcuts
          1. Show Hidden Items
            1. User Profile or C:\ProgramData Configuration Files
              1. AppData Configuration Files
                1. Hide Hidden Items
                2. Removing Old Entries from the Path
                3. Installing Anaconda
                  1. winget Command Line Based Installation
                    1. Adding the Anaconda (base) env to the Windows Env Path
                      1. The General User Interface Installer
                      2. The conda package manager
                        1. Syntax
                          1. conda list
                            1. conda update
                              1. conda install
                              2. The Anaconda Navigator
                                1. Anaconda Navigator Preferences
                                2. Spyder
                                  1. Spyder Preferences
                                  2. JupyterLab
                                    1. JupyterLab Preferences File
                                    2. Visual Studio Code
                                      1. winget Command Line Based Installation
                                        1. Installing the Python Extension
                                          1. Selecting the Python Interpreter
                                            1. The General User Interface Installer
                                            2. conda and conda-forge channels
                                              1. conda environments
                                                1. Install Latest Spyder 5 to New conda env
                                                  1. Install Latest JupyterLab 3 to New conda env
                                                  2. Spyder 5 IDE Tutorial
                                                    1. Spyder Preferences
                                                      1. File Menu
                                                        1. Syntax Highlighting
                                                          1. Run Script
                                                            1. Variable Explorer
                                                              1. Script Editor and Console
                                                                1. Kernel
                                                                  1. Cells
                                                                    1. Importing DataScience Libraries
                                                                      1. Files
                                                                        1. Plotting
                                                                        2. JupyterLab 3 IDE Tutorial
                                                                          1. File Explorer
                                                                            1. Text File
                                                                              1. Markdown File
                                                                                1. Headings
                                                                                  1. Formatted Text
                                                                                    1. Escape Characters
                                                                                      1. Spacing
                                                                                        1. Bullet Points
                                                                                          1. Tables
                                                                                            1. Links and Images
                                                                                              1. Code
                                                                                                1. Equations (Latex)
                                                                                                2. Notebook File
                                                                                                  1. Markdown and Code Cells
                                                                                                    1. Code Completion
                                                                                                      1. Cell Output
                                                                                                        1. Plotting
                                                                                                          1. Opening JupyterLab Files
                                                                                                            1. Kernel
                                                                                                              1. Shortcut Keys
                                                                                                            2. Visual Studio Code IDE Tutorial
                                                                                                              1. File Explorer
                                                                                                                1. Python Script .py Files
                                                                                                                  1. Markdown File .md
                                                                                                                    1. Notebook Files .ipynb
                                                                                                                      1. Microsoft Intelligence Code Completion
                                                                                                                        1. Terminal
                                                                                                                        2. Using Python

                                                                                                                          Uninstalling and Purging an Old Anaconda Installation

                                                                                                                          Skip this if this is a clean Installation of Windows and no previous Anaconda, Miniconda, Spyder or Python have previously been installed.

                                                                                                                          Uninstalling

                                                                                                                          Right click the Start Button to get to the Powers User Menu and select Apps and Features:

                                                                                                                          Search for Anaconda3 and then select options:

                                                                                                                          Select Uninstall:

                                                                                                                          Select Next:

                                                                                                                          Select Uninstall:

                                                                                                                          Select Next:

                                                                                                                          Select Finish:

                                                                                                                          Uninstall Miniconda, Python, Spyder and Kite if these have previously been seperately installed.

                                                                                                                          Purging Old Configuration Files

                                                                                                                          Skip this if this is a clean Installation of Windows and no previous Anaconda, Miniconda, Spyder or Python have previously been installed.

                                                                                                                          Old Start Menu Shortcuts

                                                                                                                          The Anaconda uninstaller does not appear to remove Desktop Shortcuts to Uninstalled conda environments. These need to be manually removed.

                                                                                                                          Go to the Start Menu and look for any Anaconda folder.

                                                                                                                          Right click one of the icons and select More and then Open File Location:

                                                                                                                          Go up a level (pressing [Alt] and [ ↑ ]):

                                                                                                                          Delete the Anaconda folder:

                                                                                                                          Show Hidden Items

                                                                                                                          Open up File Explorer and select Options, Show and check Hidden Items:

                                                                                                                          User Profile or C:\ProgramData Configuration Files

                                                                                                                          If Anaconda was installed for a single user it would be installed in the User Profile which can be accessed by going to the address bar and typing in:

                                                                                                                          %UserProfile%

                                                                                                                          Delete the Anaconda3 folder if present (this should have been removed when you Uninstalled Anaconda). Delete the .conda, .continuum, .ipython, .jupyter, .matplotlib, .spyder-py3folders and the .condarc file. Delete the .kite or kite folder if present:

                                                                                                                          If Anaconda was installed for All Users it would have been installed in:

                                                                                                                          C:\ProgramData

                                                                                                                          Delete the Anaconda3 folder if present (this should have been removed when you Uninstalled Anaconda). Delete the .conda, .continuum, .ipython, .jupyter, .matplotlib, .spyder-py3folders and the .condarc file if present here. Delete also the jupyter folder. Delete the .kite or kite folder if present:

                                                                                                                          AppData Configuration Files

                                                                                                                          The App Data Roaming folder can be accessed by typing in:

                                                                                                                          %AppData%

                                                                                                                          The .anaconda and jupyter folders should be deleted. Delete the .kite or kite folder if present:

                                                                                                                          Press Alt and to go up a level and then select the Local folder:

                                                                                                                          Delete the conda, Jedi, pip and Spyder folders and kite folder if present:

                                                                                                                          Hide Hidden Items

                                                                                                                          The old configuration files are removed. Open up File Explorer and select Options, Show and uncheck Hidden Items:

                                                                                                                          Removing Old Entries from the Path

                                                                                                                          If an old installation of Python or Anaconda has been added to the Windows Environmental Variables Path, they should be removed. To do this right click the Start Button and select System:

                                                                                                                          Select Advanced System Settings:

                                                                                                                          Select Environmental Variables:

                                                                                                                          Highlight Path and select Edit:

                                                                                                                          Delete any entries which contain Python, Anaconda, Miniconda or other previous Python environments you created:

                                                                                                                          Installing Anaconda

                                                                                                                          Anaconda or Miniconda can be installed in the traditional way by downloading the installer and launching it and following the GUI setup or it can be installed using winget, the Windows Terminal based installation. I will cover the installation using both methods although recommend the command line based installation as you are going to be using Anaconda for Python programming.

                                                                                                                          Miniconda is a stripped more lightweight version of Anaconda. It is essentially the same installation as Anaconda but gives a more or less empty conda base environment. The Anaconda Individual Edition is designed for only Individual use and has Commercial restrictions. Miniconda doesn't have these Commercial restrictions.

                                                                                                                          winget Command Line Based Installation

                                                                                                                          The Windows Terminal can be accessed from the Power Users Menu which is accessed by right clicking the Start Button.

                                                                                                                          We want to use the Windows Terminal. This will install Anaconda for a single user i.e. is equivalent of selecting the Just Me (recommended) option in the GUI setup. This option will install Anaconda in:

                                                                                                                          %UserProfile%/anaconda3

                                                                                                                          In general we do not want to select Windows Terminal (Admin). This is equivalent to selecting the All Users option in the GUI setup and would install Anaconda in:

                                                                                                                          C:/ProgramData/anaconda3

                                                                                                                          The Windows command line package tool winget should be directly accessible from the Windows Terminal on a modern Windows build. Type in:

                                                                                                                          winget

                                                                                                                          This should display the following list of command line arguments:

                                                                                                                          If the command is not found, you may need to open up the Microsoft Store:

                                                                                                                          To the bottom left, select your Library and then select Get Updates:

                                                                                                                          Make sure App Installer is listed in your library (and if not install it):

                                                                                                                          The five commands search, list, install, upgrade and uninstall are the most commonly used. We will use search to search for the search term anaconda:

                                                                                                                          winget search anaconda

                                                                                                                          The search term reveals the App ID as Anaconda.Anaconda3, we can use this App ID to install Anaconda:

                                                                                                                          winget install Anaconda.Anaconda3

                                                                                                                          For Miniconda instead use:

                                                                                                                          winget install Anaconda.Miniconda3

                                                                                                                          winget will download Anaconda3 and silently install it using all the default options of the GUI.

                                                                                                                          Adding the Anaconda (base) env to the Windows Env Path

                                                                                                                          The GUI installer gives an option to "Add Anaconda3 to my PATH environment variable". This is "not recommended" as the Anaconda Powershell Prompt is more optimised for managing and switching between conda environments than the Windows Terminal directly. Despite not being recommended, it can be useful for the Windows Terminal to be able to access the conda base environment as it gives flexibility to use Python in external programs.

                                                                                                                          At current winget doesn't have any flags to enable such advanced options so the default option, not to "Add Anaconda3 to my PATH environmental variable" is mandated.

                                                                                                                          We can manually add the conda base environment to the PATH environmental variables. Right click the Start Button and select System:

                                                                                                                          Select Advanced System Settings:

                                                                                                                          Select Environment Variables:

                                                                                                                          Select Edit:

                                                                                                                          Select New:

                                                                                                                          For an Anaconda installation in your user profile use:

                                                                                                                          %UserProfile%\anaconda3
                                                                                                                          %UserProfile%\anaconda3\Library\mingw-w64\bin
                                                                                                                          %UserProfile%\anaconda3\Library\usr\bin
                                                                                                                          %UserProfile%\anaconda3\Library\bin
                                                                                                                          %UserProfile%\anaconda3\Scripts

                                                                                                                          For a Miniconda installation in the user profile use:

                                                                                                                          %UserProfile%\miniconda3
                                                                                                                          %UserProfile%\miniconda3\Library\mingw-w64\bin
                                                                                                                          %UserProfile%\miniconda3\Library\usr\bin
                                                                                                                          %UserProfile%\miniconda3\Library\bin
                                                                                                                          %UserProfile%\miniconda3\Scripts

                                                                                                                          For an Anaconda installation in ProgramData (All Users) use:

                                                                                                                          C:\ProgramData\anaconda3
                                                                                                                          C:\ProgramData\anaconda3\Library\mingw-w64\bin
                                                                                                                          C:\ProgramData\anaconda3\Library\usr\bin
                                                                                                                          C:\ProgramData\anaconda3\Library\bin
                                                                                                                          C:\ProgramData\anaconda3\Scripts

                                                                                                                          For an Minicondainstallation in ProgramData (All Users) use:

                                                                                                                          C:\ProgramData\miniconda3
                                                                                                                          C:\ProgramData\miniconda3\Library\mingw-w64\bin
                                                                                                                          C:\ProgramData\miniconda3\Library\usr\bin
                                                                                                                          C:\ProgramData\miniconda3\Library\bin
                                                                                                                          C:\ProgramData\miniconda3\Scripts

                                                                                                                          Move the items up to the top and then close:

                                                                                                                          Now close any open Windows Terminal and reopen to refresh the changes. You should be able to use the following commands directly from the Windows Terminal which will be discussed later:

                                                                                                                          conda
                                                                                                                          python
                                                                                                                          spyder
                                                                                                                          jupyter-lab

                                                                                                                          Note that the conda activate envname command where envname is the name of your conda environment will not work. When using the Windows Terminal, the conda environment specified in your Environment Variables path will always be selected which is the (base) conda environment:

                                                                                                                          conda activate envname

                                                                                                                          The General User Interface Installer

                                                                                                                          If you have already installed Anaconda using winget, skip this section as Anaconda is already installed.

                                                                                                                          The Anaconda or Miniconda installers are accessible from their perspective software download pages:

                                                                                                                          Double click the installer to begin:

                                                                                                                          Select Next:

                                                                                                                          Select I Agree:

                                                                                                                          Select Just Me (recommended) and then next:

                                                                                                                          Install in the default location:

                                                                                                                          %UserProfile%/anaconda3

                                                                                                                          You can optionally Add Anaconda3 to my PATH Environmental Variable which allows the Windows Terminal to access your (base) conda environment which is useful if you plan to use Python in external programs. Details about manually doing this post-installation are in the previous section.

                                                                                                                          Once you have made your option select Install.

                                                                                                                          You can then Finish the Installation:

                                                                                                                          The conda package manager

                                                                                                                          In the Start Menu, you will now see an Anaconda folder with the Anaconda Powershell Prompt which is essentially the same as Windows Powershell but optimised for using conda environments.

                                                                                                                          There is also the Anaconda Prompt but this is based on the old Windows CMD and should be depreciated.

                                                                                                                          Note that the command is prefixed with (base) this means the (base) conda environment is selected and any programs launched will therefore be launched from the (base) conda environment or any changes made will be made to the (base) conda environment. By default (base) is the only conda environment, other environments will be discussed later:

                                                                                                                          Note the similarity to the Windows Terminal:

                                                                                                                          The Windows Terminal does not have (base) prefixed. The only conda environment it will use is the one added to the Windows Environmental Variable path. The Windows Terminal cannot be used to launch programs from other conda environments or make changes to other conda environments.

                                                                                                                          We will stick to the Anaconda Powershell Prompt from here on. You have just installed Anaconda or Miniconda and this includes the conda package manager. To use it type in:

                                                                                                                          conda

                                                                                                                          This will display a number of subcommands you can use with it:

                                                                                                                          Syntax

                                                                                                                          The most important are:

                                                                                                                          conda list
                                                                                                                          conda search packagename
                                                                                                                          conda install packagename
                                                                                                                          conda remove packagename
                                                                                                                          conda update packagename

                                                                                                                          Where packagename is replaced by the package name that you are interested in. Like the Linux Terminal, the conda command can use options which have the form of a dash followed by one to two letters such as -n or -c and flags which have the form of two dashes and a full word such as –name or –channel.

                                                                                                                          The option -c and flag –channel refer to the same thing. The option is faster to type but the flag is more readable.

                                                                                                                          conda list

                                                                                                                          We can use conda list to list all the packages installed:

                                                                                                                          conda list

                                                                                                                          Since Anaconda is installed, the conda base environment has a large list of the most commonly used datascience libraries.

                                                                                                                          For simplicity I will mention only 7 of these packages which you are more likely to have some familiarity with:

                                                                                                                          python 3.9.7
                                                                                                                          numpy 1.20.3
                                                                                                                          matplotlib 3.4.3
                                                                                                                          pandas 1.3.4
                                                                                                                          seaborn 0.11.2
                                                                                                                          spyder 5.1.5
                                                                                                                          jupyterlab 3.2.1

                                                                                                                          Let's use these to understand how the conda package manager works a bit more under the hood. Let's go to the anconda3 folder. This is found in:

                                                                                                                          %UserProfile%
                                                                                                                          %UserProfile%/anaconda3

                                                                                                                          You'll notice a conda-meta subfolder:

                                                                                                                          %UserProfile%/anaconda3/conda-meta

                                                                                                                          This folder contains a collection of json files detailing all the packages installed in the base conda environment:

                                                                                                                          We can open up the Python one in Notepad++:

                                                                                                                          This tells us the package is installed in:

                                                                                                                          %UserProfile%/anaconda3/pkgs

                                                                                                                          If we open this folder:

                                                                                                                          We see the python.exe

                                                                                                                          There is also a lib sub-folder:

                                                                                                                          In the lib subfolder there is an email subfolder, this is the email module:

                                                                                                                          In this folder there is an __init__.py and when we type:

                                                                                                                          import email

                                                                                                                          We are referring to this inbuilt Python module in the email folder with the name __init__.py

                                                                                                                          A simpler inbuilt Python module is the datetime module and we reference the datatime.py file directly when we type in:

                                                                                                                          import datetime

                                                                                                                          The Data Science libraries are not "standard" Python modules and are stored in a different folder. If we have a look at their json files in conda-meta:

                                                                                                                          We see they have their own folders in pkgs:

                                                                                                                          If we have a look at the numpy base, we get a lib subfolder:

                                                                                                                          A site packages subfolder:

                                                                                                                          And a numpy subfolder:

                                                                                                                          This contains the __init__.py file and when we type:

                                                                                                                          import numpy as np

                                                                                                                          we are referencing this file.

                                                                                                                          There are also the linalg and random folders. So when we type:

                                                                                                                          import numpy.linalg as linalg
                                                                                                                          import numpy.random as random

                                                                                                                          we are referring to the __init__.py file in the linalg and the __init__.py in the random subfolders respectively.

                                                                                                                          Likewise if we have a look in conda-meta at matplotlib:

                                                                                                                          We see a matplotlib and matplolib base folder in pkgs:

                                                                                                                          If we have a look at the lib subfolder of matplotlib base:

                                                                                                                          Then the site-packages subfolder:

                                                                                                                          And matplotlib subfolder:

                                                                                                                          Here we normally type:

                                                                                                                          import matplotlib.pyplot as plt

                                                                                                                          And we reference the pyplot.py file opposed to the __init__.py and the dot in matplotlib.pyplot means the pyplot file is in the matplotlib folder i.e. in the same location as the __init__.py file of this folder.

                                                                                                                          conda update

                                                                                                                          We can use conda update with the flag –all to look for any updates for the packages within the conda base environment from the official conda channel:

                                                                                                                          conda update --all

                                                                                                                          Here multiple updates are found and one of these is the anaconda-navigator:

                                                                                                                          To proceed we need to input:

                                                                                                                          y

                                                                                                                          The packages will then download and install:

                                                                                                                          If we now go to the conda-meta folder and take Anaconda Navigator as an example. We see the json file now references version 2.1.2 and the older version referencing 2.1.1 is gone:

                                                                                                                          In the pkgs folder however both versions are available;

                                                                                                                          Only the latest version is available.

                                                                                                                          If we type in conda list followed by the flag revision, we will see the initial revision rev0 and the new revision rev1:

                                                                                                                          conda list --revision

                                                                                                                          conda install

                                                                                                                          The conda install command can be used to install a conda package (which will be discussed in more detail) when managing conda environments. The conda install command however can be used to rollback a revision which is useful if an update causes a problem:

                                                                                                                          conda install --revision 0

                                                                                                                          The Anaconda Navigator

                                                                                                                          The Anaconda Navigator is a GUI version of the conda package manager although it is somewhat limited compared to its command line based equivalent. It also contains a series of tiles for launch installed Python Development Environments.

                                                                                                                          It can be launched from the Start Menu or by use of the Anaconda Powershell prompt by typing in:

                                                                                                                          anaconda-navigator

                                                                                                                          The Anaconda Navigator shows a series of tiles for launching Python Integrated Development Environments such as Spyder and JupyterLab:

                                                                                                                          The Environments tab is essentially a GUI version of the conda package manager, think of it as a GUI version of conda list:

                                                                                                                          Anaconda Navigator Preferences

                                                                                                                          Some preferences can be changed by selecting File→Preferences:

                                                                                                                          These preferences are saved to a configuration file within:

                                                                                                                          %AppData%

                                                                                                                          There is a .anaconda subfolder and within this a navigator subfolder and within that an anaconda subfolder and within that a navigator subfolder…

                                                                                                                          The anaconda-navigator.ini file can be edited in a program like Notepad++. If there is a display issue, changing the enable_high_dpi_scaling setting to False normally resolves it:

                                                                                                                          Spyder

                                                                                                                          The Spyder IDE can be launched from, the Start Menu, its tile in the Anaconda Navigator or by using the command:

                                                                                                                          spyder

                                                                                                                          Spyder will launch and prompt you for a tour of the IDE:

                                                                                                                          Spyder Preferences

                                                                                                                          The preferences can be changed by going to Tools and then Preferences:

                                                                                                                          These preferences are found within a hidden folder within:

                                                                                                                          %UserProfile%

                                                                                                                          Called .spyder-py3:

                                                                                                                          There is a config subfolder:

                                                                                                                          And a Spyder configurations settings file which can be opened in Notepad++:

                                                                                                                          JupyterLab

                                                                                                                          JupyterLab is a browser based IDE and can be launched from its tab in the Anaconda Navigator or by using the command:

                                                                                                                          jupyter-lab

                                                                                                                          This is the only place where a dash is used within the middle of the word jupyterlab.

                                                                                                                          JupyterLab will open in the web browser as expected:

                                                                                                                          Note to close JupyterLab you need to close the tab in your web browser. This will normally keep it active in the Powershell. You will need to close the command by using the shortcut key [Ctrl] + [ c ]

                                                                                                                          The new prompt will display when closed:

                                                                                                                          JupyterLab Preferences File

                                                                                                                          A JupyterLab preference file can be generated using the command:

                                                                                                                          jupyter notebook --generate-config

                                                                                                                          This will tell you the location of the preferences file:

                                                                                                                          You can go to this location:

                                                                                                                          And edit some of the settings by uncommenting out the respective setting and changing the value to your desired preference:

                                                                                                                          Visual Studio Code

                                                                                                                          Visual Studio Code is not preinstalled with Anaconda but can easily be installed by use of winget or downloading and installing it using the GUI installer.

                                                                                                                          winget Command Line Based Installation

                                                                                                                          Right click the Start Button and select Windows Terminal:

                                                                                                                          To install Visual Studio Code input:

                                                                                                                          winget install Microsoft.VisualStudioCode

                                                                                                                          It will download and install:

                                                                                                                          You can launch Visual Studio Code from its shortcut in the Start Menu, its Tile in the Anaconda Navigator or by typing the following in the Anaconda Powershell prompt:

                                                                                                                          code

                                                                                                                          Installing the Python Extension

                                                                                                                          To use Python we must install the Python extension. To the right hand side select the Extensions Tab and then select the Python Extension and select Install:

                                                                                                                          The extension should now be installed:

                                                                                                                          Selecting the Python Interpreter

                                                                                                                          Python is inbuilt into Linux but the inbuilt Python has no Data Science libraries. Visual Studio Code uses the inbuilt Python by default meaning you'll get a module not found error if you attempt to use a Data Science library. We'll need to select the Python interpreter to use the conda (base) environment.

                                                                                                                          Press [Ctrl] + [] + [ p ] to open the Command Palette:

                                                                                                                          Search for interpreter and use your mouse click on the Python: Select Interpreter:

                                                                                                                          Change to the Python 3.9.7 (base) if not already selected:

                                                                                                                          The General User Interface Installer

                                                                                                                          If you have already installed Visual Studio Code using winget, skip this section as Visual Studio Code is already installed.

                                                                                                                          The Visual Code 64 Bit installer is accessible from the Visual Studio software download pages:

                                                                                                                          Double click the setup:

                                                                                                                          Accept the License Agreement and select Next:

                                                                                                                          Select Next:

                                                                                                                          Select Next:

                                                                                                                          Use the default options and select Next:

                                                                                                                          Select Install:

                                                                                                                          Select Finish:

                                                                                                                          Install the Python extension (see the section above).

                                                                                                                          conda and conda-forge channels

                                                                                                                          There are two "official" conda channels conda and conda-forge.

                                                                                                                          conda is maintained by the Anaconda team who spend time putting a collection of Python packages together and assessing their compatibility with one another. The conda team tend to only update most their packages once to twice a year.

                                                                                                                          conda-forge is the developer channel. This is where the developers of each package submit their packages. In many cases the packages made by small developers are available on conda-forge but not the conda channel.

                                                                                                                          This can be demonstrated for example with python-docx which is a Python library used to create a Word Document from a Python script. There are no search results on the conda channel:

                                                                                                                          conda search python-docx

                                                                                                                          To search another channel we use the option -c followed by the name of the channel:

                                                                                                                          conda search -c conda-forge python-docx

                                                                                                                          Larger more well-known packages such as Spyder are available on both conda and conda-forge. Spyder has far more frequent updates than once to twice a year and therefore there are differences between what both channels display as the latest version:

                                                                                                                          conda search spyder
                                                                                                                          conda search -c conda-forge spyder

                                                                                                                          As a result sometimes there can be a fix or improvement made to Spyder for example that will take about 6 months-1 year to be updated by the Anaconda team.

                                                                                                                          conda-forge packages can be added to your conda (base) environment when the package is relatively small and has only a handful of dependencies.

                                                                                                                          conda install -c conda-forge python-docx

                                                                                                                          The conda package manager will be able to "solve" the environment and ask you to confirm the changes. Input:

                                                                                                                          y

                                                                                                                          The package will successfully be added:

                                                                                                                          conda environments

                                                                                                                          On the other hand for packages with a huge number of dependencies… The conda package manager will likely enter an infinite loop attempting to solve your environment. This issue is common when trying to update Spyder to the latest version available on conda-forge. There is a subfolder within anaconda3 called envs:

                                                                                                                          %UserProfile%/anaconda3/envs

                                                                                                                          This is empty by default as there is only one environment the base environment:

                                                                                                                          Install Latest Spyder 5 to New conda env

                                                                                                                          Let's create a new environment called spyder.

                                                                                                                          If you had an old environment called spyder e.g. from an older version use the following to remove it:

                                                                                                                          conda remove -n spyder5

                                                                                                                          To create a new environment use:

                                                                                                                          conda create -n spyder

                                                                                                                          After inputting:

                                                                                                                          y

                                                                                                                          A spyder subfolder appears:

                                                                                                                          Note up until now all commands begin with (base) meaning the base conda environment is selected:

                                                                                                                          If we type in:

                                                                                                                          conda activate spyder

                                                                                                                          We now see that (spyder) is in place of (base). This means the (spyder) conda environment is selected. If we use conda list, conda update, conda install or conda remove it will make changes to the conda (spyder) environment and not (base). Note when the terminal is closed and opened it defaults to (base) however we can change back to (base) without closing the terminal by using:

                                                                                                                          conda activate base

                                                                                                                          Now let's install spyder from the conda-forge channel:

                                                                                                                          conda install -c conda-forge spyder

                                                                                                                          Here we see the huge number of mandatory dependencies for the latest version of the Spyder 5 IDE:

                                                                                                                          To install them input:

                                                                                                                          y

                                                                                                                          To launch spyder from the (spyder) conda env input:

                                                                                                                          spyder

                                                                                                                          We can see we are using the newer Spyder by going to Help→About:

                                                                                                                          If we go to Help→Dependencies, we can see that the optional dependencies are not installed, meaning we'll get module not found errors if we attempt to use a Data Science library:

                                                                                                                          To rectify this we can use:

                                                                                                                          conda install -c conda-forge cython seaborn sympy openpyxl xlrd xlsxwriter lxml sqlalchemy scikit-learn

                                                                                                                          Input:

                                                                                                                          y

                                                                                                                          to proceed.

                                                                                                                          We now have the mandatory and optional dependencies installed for Spyder.

                                                                                                                          You can add other packages to this conda environment if you need them using a similar install command to the above.

                                                                                                                          Ensure you remember to activate the environment before launching spyder.

                                                                                                                          To periodically check for updates for this spyder conda environment from the conda-forge channel, activate the spyder conda environment and use:

                                                                                                                          conda activate spyder
                                                                                                                          conda update -c conda-forge --all

                                                                                                                          Install Latest JupyterLab 3 to New conda env

                                                                                                                          The procedure to install the latest version of JupyterLab in a conda environment is similar.

                                                                                                                          Remove an old conda env if present:

                                                                                                                          conda remove -n jupyterlab3

                                                                                                                          Install JupyterLab plus optional dependencies:

                                                                                                                          conda create -n jupyterlab
                                                                                                                          conda activate jupyterlab
                                                                                                                          conda install -c conda-forge jupyterlab
                                                                                                                          conda install -c conda-forge cython seaborn sympy openpyxl xlrd xlsxwriter lxml sqlalchemy scikit-learn
                                                                                                                          conda install -c conda-forge nodejs ipywidgets 
                                                                                                                          jupyter-lab

                                                                                                                          Install optional JupyterLab extensions such as the variable inspector, interactive matplotlib, plotly and drawio:

                                                                                                                          conda install -c conda-forge jupyterlab-variableinspector ipympl plotly jupyterlab-drawio

                                                                                                                          To periodically check for updates for this jupyterlab conda environment from the conda-forge channel, activate the jupyterlab conda environment and use:

                                                                                                                          conda activate jupyterlab
                                                                                                                          conda update -c conda-forge --all

                                                                                                                          Spyder 5 IDE Tutorial

                                                                                                                          Spyder 5 is one of the best IDEs for learning Python and one of the most popular for DataScience.

                                                                                                                          Spyder Preferences

                                                                                                                          The Spyder Preference can be altered by going to Tools and Preferences:

                                                                                                                          In the Appearance Tab, the syntax highlighting theme can be changed from Spyder Dark to Spyder:

                                                                                                                          In the Editor, Indent Guides and Blank Spaces can be shown:

                                                                                                                          Select Apply and then Yes:

                                                                                                                          Spyder will restart using the Spyder Syntax highlighting scheme:

                                                                                                                          File Menu

                                                                                                                          Spyder has a file menu to save and open script files. Each script displays in its own tab. The current directory (the directory the last script is run) shows at the top:

                                                                                                                          We can save our script file in Documents for example:

                                                                                                                          In this case I will call it spyder_script

                                                                                                                          Now it displays at the top and changes aren't saved so it is indicated with a *

                                                                                                                          Syntax Highlighting

                                                                                                                          Syntax highlighting is carried out by default. Numeric values on line 2 and 3 are highlighted in brown. strs on line 7, 14, 15 and 16 are highlighted in green.

                                                                                                                          Note the matching bracket for the bracket selected on line 16 is highlighted in line 14.

                                                                                                                          There is a typo in the code and this is marked by an x on line 16 as the variable boll_num isn't defined:

                                                                                                                          Once this is fixed, there is no error:

                                                                                                                          Run Script

                                                                                                                          We can put some test code to create fundamental numeric variables and text variables. We can also create collections using the inbuilt classes:

                                                                                                                          #%% Fundamental Numeric Datatypes
                                                                                                                          full_num = 5
                                                                                                                          dec_num = 10.5
                                                                                                                          bool_num = True
                                                                                                                          
                                                                                                                          #%% String
                                                                                                                          string = "Hello"
                                                                                                                          
                                                                                                                          #%% Collections
                                                                                                                          list_col = [full_num, dec_num, bool_num, string]
                                                                                                                          tuple_col = (full_num, dec_num, bool_num, string)
                                                                                                                          dict_col = {"full": full_num, "dec": dec_num, "bool": "bool_num", "string": string}
                                                                                                                          

                                                                                                                          Upon first launch we are prompted for the run settings which we can leave as default (these can later be changed in preferences if desired):

                                                                                                                          Variable Explorer

                                                                                                                          Spyder has a Variable Explorer which can be used to explore these variables. Each variable type is listed, alongside its size. In the case of a string, this is the number of characters and in the case of a list, this is the number of items in the list. Collections of variables for example this dict can be expanded to view in more detail:

                                                                                                                          Script Editor and Console

                                                                                                                          Spyder has a script editor and a console. The console keeps a track of the number of executions sent to the kernel. For example if the script is run to create the variable full_num, the value of full_num is shown in the variable explorer and we are informed in the console that we have run the script file:

                                                                                                                          full_num = 5

                                                                                                                          If we modify the script to print full_num and run it again:

                                                                                                                          full_num = 5
                                                                                                                          print(full_num)

                                                                                                                          The number of execution is now 2 and we are informed the script is run. The value 5 also displays below this as we used the print function:

                                                                                                                          Operations can be carried out in the console. For example this single line operation was the third execution to take place:

                                                                                                                          The console is often used to test out a quick line or two of code before adding it to a script.

                                                                                                                          Kernel

                                                                                                                          Restarting the Kernel will clear all variables from the Variable Explorer, clear the Console and close any imported modules. The number of executions will return back to 0.

                                                                                                                          The Kernel can be Restarted by going to Consoles → Restart Kernel:

                                                                                                                          Select Yes to Proceed:

                                                                                                                          The Kernel is now clear:

                                                                                                                          Cells

                                                                                                                          Comments can be added to the script by beginning with #. If a line begins with #%% it will create a new cell and the currently selected cell is highlighted in yellow.

                                                                                                                          We can run a single cell by selecting run cell:

                                                                                                                          Notice only the variables defined in the first cell display in the variable explorer and the first cell is still highlighted:

                                                                                                                          We can restart the Kernel and instead, select the next button. Run the cell and move onto the next cell:

                                                                                                                          Notice how the second cell is highlighted after the first cell is executed:

                                                                                                                          Finally we can use the 4th Run button to run only the highlighted selection:

                                                                                                                          Importing DataScience Libraries

                                                                                                                          Supposing we want to record some dependent y data values with respect to independent x values. We could use two lists to create two equally sized numeric vectors, a nested list or a dictionary:

                                                                                                                          x = [1, 2, 3, 4, 5]
                                                                                                                          y = [2, 4, 6, 8, 10]
                                                                                                                          
                                                                                                                          xy = [[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]]
                                                                                                                          
                                                                                                                          xy2 = {"x": [1, 2, 3, 4, 5], "y": [2, 4, 6, 8, 10]}

                                                                                                                          Note however that each of these objects is 1 dimensional. i.e. xy is a list of lists.

                                                                                                                          Moreover the datatype of each item in the list can be independent which offers the most flexibility but it is not particularly useful in some cases where one is trying to plot the data to see a trend for example.

                                                                                                                          Finally the operators available for a collection such as a list are not optimised for numeric data. The + operator for example will concatenate a two lists, making a longer list, in a similar manner to the + operator being setup between two strings. It is not setup like the + operator between two ints which perform numeric addition.

                                                                                                                          We have two Python libraries based upon additional datatypes, numpy which is based numeric python arrays (which can be visualised as a mathematical matrix) and pandas which is based upon a DataFrame (which can be visualised as an Excel spreadsheet). These datatypes have a number of methods and operators, for example in the case of a numeric array, will carry out matrix operations.

                                                                                                                          Let's first examine numpy. Note the import line should be highlighted and ran which will execute it as shown in the console:

                                                                                                                          As numpy is imported into the kernel, code-completion for numpy will be accessible. In the case of np. a selection of objects which can be called from the numpy library:

                                                                                                                          We can use the function array to create a new numpy array. When this function is typed with parenthesis, details about the functions input arguments are shown.

                                                                                                                          Spyder has a Help Pane. Highlighting a function or class and pressing Ctrl + i will inspect it:

                                                                                                                          And attempt to retrieve the documentation:

                                                                                                                          For functions or classes from the DataScience libraries this can sometimes be quite limited and only give details about the library and not the specific function or class:

                                                                                                                          Usually a more detailed docstring can be accessed directly from the console by typing in a ? followed by the function or class to be investigated:

                                                                                                                          ? np.array

                                                                                                                          Use the mouse wheel to scroll through the documentation and press q to quit the pager:

                                                                                                                          This will take you to the next line in the console:

                                                                                                                          We need the object which is usually a list or a list of lists. Everything else shown is optional and the datatype will be automatically determined:

                                                                                                                          import numpy as np
                                                                                                                          x = np.array([1, 2, 3, 4, 5])
                                                                                                                          y = np.array([2, 4, 6, 8, 10])
                                                                                                                          xy = np.array([[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]])
                                                                                                                          xy2 = np.transpose(xy)

                                                                                                                          If we run the code above we can see all the objects in the variable explorer. Since the datatype is constant for each cell in a numpy array, this is just shown on the Variable Explorer:

                                                                                                                          We can now look at the pandas. Once again the import line should be ran in order to allow the code-completion to work:

                                                                                                                          In pandas we use the DataFrame (CamelCaseCapitalization) class to create an instance (our variable name xy):

                                                                                                                          We need to supply the data. This is provided in the form of a dictionary where they keys are strings of the column names and the values are lists. Notice how the dataframe xy looks like a matrix but each column is clearly labelled as "x" and "y" respectively:

                                                                                                                          Files

                                                                                                                          Notice the dataframe is in the form of an excel sheet and closely resembles the one below:

                                                                                                                          We can use the read_excel function to read this data and create a new instance of a dataframe.

                                                                                                                          This Excel File has the title "Book1.xlsx" and is in the same folder as the spyder_script.py file. These can be seen by using the Files Tab. Each column has a name and the default Sheet name Sheet1 is used. Therefore we don't need to override the default values of any of the keyword input arguments in the read_excel function.

                                                                                                                          This reads in the data as a dataframe: