# The Anaconda Python Distribution

## Installing the Anaconda Python Distribution with the Spyder 5 IDE and JupyterLab 3 IDE on Windows 11 and Best Practices for Managing a conda Environment

Python beginners are recommended to install Anaconda opposed to installing Python…

### What is Anaconda/Miniconda and what is the difference with Python?

Anaconda is a Python distribution. The Anaconda Python distribution contains the conda package manager which can be used to install Python conda (the Anaconda official channel, maintained by the Anaconda company) or conda-forge (the Community/Developer channel) packages. Anaconda also includes a base environment which contains the core Python programming language and its inbuilt modules, the Spyder and JupyterLab Integrating Development Environments (IDEs), and the most common libraries or modules for data science such as numpy, scipy, pandas, matplotlib and seaborn as well as a multitude of others. IDEs can be thought as programs for working with Python code, similar to how one might use Libre Office or Microsoft Word to work with a document.

Miniconda has the same conda package manager as Anaconda but instead of having a versatile base environment packed together with data science libraries it essentially has an empty base environment. Although the base environment can be modified, it is recommended to create your own conda environment opposed to modifying the base environment in most cases.3

In both Miniconda and Anaconda a conda environment can be created from scratch. In theory new users can just install Anaconda and use the base conda environment directly. Unfortunately the Anaconda team are very slow in updating the IDEs (Spyder specifically) in the base conda environment and there are conflicts in the conda base environment that cannot be solved when attempting to update these IDEs. This guide will instruct in creating a new conda environment for the Spyder IDE and a new conda environment with the JupyterLab IDE. It will use the Anaconda Individual Edition but the instructions are more or less equally applicable to Miniconda.

### Why have a Python distribution and use the conda package manager?

The conda package manager performs a number of checks for incompatibilities when the user attempts to install additional Python modules. Such compatibilities arise when one module is dependent on another. The seaborn library for example is a plotting library for data visualization and acts as a wrapper around the matplotlib plotting library. The matplotlib plotting library itself is dependent on numpy which is used for array manipulation. When the user blindly installs the latest version of Python and then numpy and then matplotlib and then seaborn incompatibilities are very likely to arise. If an underlying object in numpy is changed or deprecated, this can in turn break the functionality of matplotlib which can in turn break the functionality of seaborn and so on and so forth. This can lead to endless frustrations particularly for a new user who doesn't yet know what they are doing. Such frustrations are alleviated to a great extent by use of the conda package manager.

### Cost and Licensing

Python alongside the most commonly used data science libraries included in the Anaconda Python distribution can be used as an open-source alternative to expensive commercial scientific software such as MATLAB. This guide will focus on installation of Python and at the end link to additional guides which I put together which examine the use of Python to replace MATLAB functionality.

Anaconda itself is a company. The Anaconda Individual Edition is Free but as the name suggests designed only for Individual use. Anaconda has a Commercial, Team and Enterprise Edition for Commercial use. The license essentially includes product support for Commercial use from the Anaconda company and funds the software development (similar to RedHat with Fedora and RedHat Enterprise Linux). The Team and Enterprise Editions may include additional support when it comes to rolling out a custom base environment for a Team or Large Corporation of Data Scientists for example.

Miniconda has the same conda package manager as Anaconda and an empty base environment. Miniconda can be used with the conda-forge community channel for Free and does not have the commercial restrictions included in the Anaconda Individual Edition.

### Operating System

Anaconda is compatible with Windows, Linux and Mac.

This guide is Windows focused and will use Windows 11 but instructions are more or less identical for windows 10 64 Bit. Windows 7 64 Bit is not supported as it has reached End of Life. There are usually no installation issues on a clean install of Windows. Installation issues usually arise when there is an old Anaconda installation present. Unfortunately the uninstaller does not purge the system of all the old configuration files which may reintroduce a problem after a reinstallation if they are problematic. I have included additional instructions to uninstall and purge an old installation in this scenario.

Installation on Linux is slightly different, a shell script has to be launched via the Terminal. After installation there are no Start Menu shortcuts created on Linux and the Terminal has to be used to launch the Anaconda Navigator. This can be confusing for new users. The differences are outlined in the separate Linux installation guide:

## Videos

For those experienced with the conda package manager. The following lines of code can be used in the Anaconda PowerShell Prompt or the Miniconda PowerShell Prompt. This is explained in more details in subsequent sections for beginners.

Update the conda base environment and conda package manager to the latest version:

conda update --all

Clone a conda environment:

conda create -n base2 --clone base

Create a new environment for Spyder 5.1.5:

conda create -n spyder515
conda activate spyder515
conda config --set channel_priority strict
conda install spyder=5.1.5
conda install cython matplotlib numpy pandas scipy sympy seaborn openpyxl xlrd xlsxwriter
spyder

Create a new environment for JupyterLab 3.1.14 with additional Lab Extensions:

conda create -n jupyterlab3114
conda activate jupyterlab3114
conda config --set channel_priority strict
conda install jupyterlab=3.1.14
conda install cython matplotlib numpy pandas scipy sympy seaborn openpyxl xlrd xlsxwriter
conda install nodejs ipywidgets jupyterlab-variableinspector ipympl plotly jupyterlab-drawio
jupyter-lab

To list conda environments and delete old conda environments use replacing spyder514 and jupyterlab3113 with the name of your old conda environment:

conda env list
conda env remove -n spyder514
conda env remove -n jupyterlab3113

## Uninstalling Anaconda and Kite

### Uninstalling Anaconda

Anaconda can be uninstalled from Apps and Features. Right click the Start Button and select Apps and Features:

Select Anaconda3 and then select Uninstall:

Select Uninstall:

Select Next:

Select Uninstall:

Select Next:

Select Next:

Select Reboot Now and then Finish:

### Uninstalling Kite

Kite can also be uninstalled from Apps & Features:

Select Uninstall:

Accept the User Account Control Prompt:

Select Close:

### Purging the Anaconda Configuration

Unfortunately when Anaconda is uninstalled, it leaves a lot of configuration files behind. Sometimes one of these files can be corrupted or have bad settings which will be retained when Anaconda is reinstalled.

Press [⊞] and [ e ] to open up file explorer. To the top select Settings → Show → Hidden Items:

To get to your user profile type in the following in the Windows Explorer Address Bar:

%UserProfile%/

Then delete the .conda, .ipython, .jupyter, .matplotlib, .spyder-py3, anaconda3 folders and the .condarc file:

Now type the following into the Windows Explorer Address Bar:

%AppData This will take you to the AppData Roaming folder: Delete the .anaconda, jupyter and kite folders: Press [Alt] + [↑] to go up a folder and then select the Local Subfolder instead of the Roaming subfolder. Delete the conda, Kite, pip and Spyder folders (do not delete the Packages folder). ## Installation ### Installing Anaconda The Anaconda Individual installer or Miniconda installer can be downloaded from the Anaconda website: Select Download: Double click the installer: Select Next: Select I Agree: Select "Just Me" and then Next: By default an anaconda3 or miniconda3 folder will be created in your user directory. Note installation may fail if there is a space in your user directory. Select Next: Under Advanced options select both Add Anaconda to my PATH environment variable (this option will allow you to access Python directly from the Windows Terminal (PowerShell) opposed to just Anaconda Powershell Prompt) and Register Anaconda3 as my default Python 3.8. The difference between these will be explaned in more depth later on: Select Next: Select Next: You can opt to view the getting started tutorials. Select Finish: ### The pip (Python install package) command In Python library documentation you will see frequent references to pip (Python install package). When using a conda environment, although the Anaconda Powershell Prompt recognises the: pip install package-to-be-installed command, it is frequently problematic. It should be avoided where possible as there is normally a conda equivalent command that behind the scenes performs additional checks to solve (address any conflicts and check for dependencies) the conda environment. Search for the name of your package on the Anaconda Website before following any other installation instructions involving pip ### The conda command We will use the conda command to use the conda package manager. Let's first update the Anaconda Python Distribution. Go to the Windows 11 Start Menu and launch the Anaconda PowerShell Prompt: This will open up the Anaconda PowerShell Prompt. To the left hand side in parenthesis the currently selected conda environment will be selected (more details about this later). The default environment is called base: #### conda Open up the Anaconda PowerShell Prompt and type in: conda #### conda list This will give you details about the positional arguments. Most notable are: conda list This will list all the currently installed Python libraries in the currently selected conda environment. The default conda environment is the base conda environment and in the Anaconda PowerShell Prompt we can see that it is selected. We can use the optional argument name to specify the conda environment explicitly: conda list --name base Because this optional argument is so commonly used it can be abbreviated using: conda list -n base Note the parenthesis to the left hand side (base) tells us that the base environment is selected. Therefore we do not need to include it as an optional input argument. We can use: conda list #### conda update The next positional input argument is update. update has to be followed by the name of the library we wish to update. In the vast majority of cases when update is used the optional argument –all is used which updates everything to the latest versions the Anaconda team have tested and deemed stable. In the case of Anaconda this is everything in the conda base environment and in the case of Miniconda this is only the conda package manager itself: conda update -all You will be told about all the packages being updated. Input y To proceed: Anaconda should now be updated: The next command is search. search by default will search the official conda channel for all versions of a library. Let's use jupyterlab as an example: conda search jupyterlab We see all the versions of jupyterlab we can install. The currently installed version (c.f. the output from conda list) is 3.0.14 which is the latest listed: We can use the optional argument –channel to explicitly specify the repository or channel to search: conda search --channel conda jupyterlab Because channel is so commonly used, it can be abbreviated using: conda search -c conda jupyterlab The conda-forge community channel is used by developers of Python IDEs and individual Python libraries. In general the developer submit their latest version to the conda-forge community channel and if the product is commonly used it is also later tested by the Anaconda team and added to Anacondas official conda channel. Note: not all the Python libraries are mainstream and not all versions of a mainstream library are tested by the Anaconda team for example if the developer releases a version with a bug and in quick succession a newer version to address the bug, the Anaconda team may only test the newer version. There are also some products where development has been stopped on the conda-forge channel and versions are directly released on the conda channel by the Anaconda team. It is usually therefore worthwhile checking both channels for the latest version. Some developers such as plotly also maintain their own channel/repository seperately. conda search -c conda-forge jupyterlab In the example above we see that the latest version on the conda channel is 3.0.14 (currently installed) however there is a newer version 3.0.16 on the conda-forge channel. #### conda install The Anaconda base environment is large, meaning a lot of packages are installed each which have their own dependencies. Installing a small package with few dependencies to a base environment will usually work however installing a large package such as the latest version of the Spyder IDE which has a lot of dependencies which may conflict with other packages may not work. The conda package manager will get stuck on solving the environment. To install this latest version we can use the install positional argument alongside the optional arguments -n to specify our conda environment and -c to specify the conda forge channel. Usually it also helps to specify the version we wish to install: conda install -c conda-forge -n base jupyterlab=3.0.16 The Anaconda Powershell Prompt will take some time to get the package information and attempt to solve the conda environment. Essentially it will look for all the dependencies for JupyterLab 3.0.16 and prompt to install or update other packages to compatible versions which accommodate JupyterLab. It will also check if updating these packages has an influence on any of the other packages installed in the conda environment. You will be warned if incompatible packages are removed or downgraded. Input: y To proceed: The packages will be downloaded and installed and any other stated change in package version will be carried out. You will see a new prompt when the operation is finished: We can repeat the same procedure with Spyder: conda search -c conda spyder At the time of writing the latest version is 5.0.5 on the conda channel: conda search -c conda-forge spyder At this current moment in time, the conda-forge channel has a more recent version of Spyder 5.1.5 which has a number of fixes, particularly with regards to the speed of Kite code auto-completion: In theory spyder can be installed using: conda install -c conda-forge -n base spyder=5.1.5 In practice, spyder is an IDE which has a large number of dependencies and there are some conflicts with packages found in the base environment. conda will attempt to solve these incompatibilities and you will see: Solving environment: failed with initial frozen solve. Retrying with flexible solve. Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source. Collecting package metadata (repodata.json): done Solving environment: Unfortunately it seems to hang forever: To cancel the operation we need to press [Ctrl] + [ c ] and then confirm the cancellation with: y Installation of Spyder 5.0.5 to the base environment works but this version has a number of serious bugs including a huge delay in Kite autocompletion. Essentially the Anaconda team need to update their base environment and standalone installer for Spyder 5.1.5 however are very slow to do this (being 1-2 months behind the Spyder team). ## Conda Environment for Spyder 5.1.5 In the meantime we can create our own conda environment specifically for Spyder 5.1.5. ### base conda environment Before creating a new conda environment it is worthwhile taking some time to understand the base conda environment. The base conda environment is found in: %UserProfile%/Anaconda3 This folder contains the python.exe: It also contains a lib folder which contains standard Python libraries: And this contains a site-packages folder which contains the additional Python libraries installed by Anaconda: You will see a numpy, pandas, matplotlib, seaborn, spyder, jupyterlab folders listed here: ### Create a new conda environment In the base conda environment you will see a folder called envs: %UserProfile%/Anaconda3/envs This folder is going to be empty by default. A conda environment is essentially a sub installation, we can install a specific Python version, a specific set of Python libraries required for a project. We can create a new conda environment for spyder 5.1.5 using: conda create -n spyder515 Where spyder515 is the name of the conda environment. To proceed input: y You will see the new folder testenv appear which is largely empty because this is an empty conda environment: ### Activate a conda environment Notice that each prompt in the Anaconda Powershell Prompt begins with (base), this denotes that the base environment is selected. Any conda command such as conda list, conda install .. and conda update … will list, install and update the base installation. To select (or activate) another conda environment we can use: conda activate spyder515 Notice how the Anaconda Powershell Prompt now begins with (spyder515), this means any conda command such as conda list, conda install .. and conda update … will list, install and update the spyder515 installation. Note when the Anaconda Powershell Prompt is closed and relaunced, base will automatically be reselected. Note that the Windows Terminal does not begin with the (base) or (spyder515) and the activate command does not work in Windows Terminal which uses the Anaconda Environment specified in the Windows Environmental Variable Path (more details later). ### conda environment channel Settings Let's now change add the conda-forge channel and set the channel priority to strict: conda config --add channels conda-forge conda config --set channel_priority strict ### Installing Spyder 5.1.5 Now that the spyder515 env is selected and the env is configured to use the conda-forge channel we can search for spyder: conda search spyder The latest version of spyder 5.1.5 is listed: To install Spyder 5.1.5 to the conda environment spyder515 from the conda-forge channel, we can explictly use: conda install -c conda-forge -n spyder515 spyder=5.1.5 Alternatively because the spyder515 env is selected and the conda-forge channel is added we can install it using: conda install spyder=5.1.5 Spyder alongside all its mandatory dependencies (for example Python) will be listed: To proceed input: y You will see the folder fill with files, including a python.exe There will be a lib subfolder and within that a site-packages subfolder where you see spyder get installed: Spyder has mandatory and optional dependencies and only the mandatory dependencies are installed by default: You are more than likely going to want to install these optional dependencies alongside some others such as seaborn, a wrapper around matplotlib which includes plot styles and additional plot types and openpyxl for reading excel files within pandas: conda install cython matplotlib numpy pandas scipy sympy seaborn openpyxl Alternatively we can explicitly state the channel used and name of the environment: conda install -c conda-forge -n spyder515 cython matplotlib numpy pandas scipy sympy seaborn openpyxl To proceed input: y Your new conda environment spyder515 should now have Spyder 5 installed alongside all its dependencies: Your Start Menu will be updated to include a folder corresponding to your conda env Spyder. The conda environment will be included in parenthesis (spyder515) which corresponds to spyder515 or (anaconda3) which corresponds to base respectively: ### Clone a conda environment When experimenting with new packages, it is sometimes useful to clone a stable conda environment. For example if we wish to clone the env spyder515 to the clone with the name spyder515a. We can use: conda create -n spyder515a --clone spyder515 This will create the cloned environment in a new folder corresponding to the clones name: Once again to use this environment, we need to activate it. ### Remove a conda environment We can use the env optional argument with remove to remove a conda environment. For example if we wish to remove the cloned environment: conda env remove -n spyder515a Doing so will remove all the packages but may leave some empty folders behind. Once the env has been removed, the spyder515a folder may be deleted within Windows Explorer. ## The Anaconda Navigator The Anaconda Navigator is a simple general user interface which lists all of the Python IDEs installed within the Anaconda Python distribution and has a general user interface for installing packages. In practice however it is very buggy and installing packages via the Anaconda Powershell Prompt is usually more reliable. ### Launching the Anaconda Navigator You can launch the Anaconda Navigator for the base environment from the Start Menu: Anaconda comes with a number of IDEs preinstalled. These can be launched by clicking their respective tile and selecting launch. Other IDEs can be Installed via Anaconda and then subsequently launched. This guide will only focus on two IDEs, Spyder and JupyterLab: Anaconda is supposed to otherwise be a GUI interface of managing environments i.e. a GUI version of the conda command in the Anaconda Powershell Prompt. The environments tab is similar to conda list with a limited options for updating packages to stable versions tested by the Anaconda company. The Anaconda Navigator is however very buggy and is rarely used in comparison to direct command line arguments from the Anaconda Powershell Prompt. Note you can launch the Anaconda Navigator from the Anaconda Powershell Prompt by first selecting the conda environment and then launching anaconda-navigator: conda activate spyder515 anaconda-navigator ### Anaconda Navigator Preferences The Anaconda Navigator has a high DPI setting however it doesn't handle High DPI screens with a Display Scaling at 200 % very well. In my XPS 13 9365 the Tiles are too large to move. If you have this issue you can try and select File → Preferences: In theory you should be able to uncheck the High DPI Settings and select Apply: On my XPS 13 9365, this dialog window was too big and I could not get to these options. If you are in this situation, close Anaconda Navigator. Open file explorer by pressing [⊞] and [ e ] and then in the address bar type in: %AppData% Select the .anaconda, then navigator and then .anaconda and then navigator subfolder. Right click anaconda-navigator configuration settings and select open with notepad: Change the line: enable_high_dpi_scaling = False You should be able to relaunch the Anaconda Navigator and see the tiles at normal size. The anaconda navigator can be launched from the anaconda powershell prompt by typing: anaconda-navigator ## Spyder IDE ### Launching Spyder Spyder can be launched from its own start Menu shortcut, from its tile in the Anaconda Navigator or from the Anaconda PowerShell Prompt by selecting the conda environment and typing in: conda activate spyder515 spyder When you first launch Spyder you will get a welcome tour: ### Installation of Kite Coding Assistant If you haven't already been prompted by Spyder to install Kite. Select Tools → Install Kite Autocompletion Engine: Then select Install Kite: The Spyder IDE will download the Kite Setup: If you get an error, download Kite Manually and begin the installation: Once downloaded the installation will hang until the User Account Control Prompt is selected: Accept the User Account Control Prompt: Kite should prompt you to optionally log in with an email. Select continue: Select Let's Go: Kite will then perform a background check for Python IDE plugins: If it doesn't find any, it will prompt you to install editor plugins: To install the Spyder IDE plugin you will have to close Spyder: Once Spyder is closed, select Install: The Spyder Kite plugin should now be installed: A Kite tutorial will open up when you launch Spyder: ### Spyder Preferences To change your Spyder Preferences, select Tools and Preferences: Then under Appearance you can optionally change from the default Spyder Dark Syntax Highlighting theme to the Spyder (Light) Syntax highlighting theme. I will also increase the text size slightly (so screenshots are easier to read). Once you have made your changes, select Apply: You will be prompted to restart Spyder in order to apply the changes: You will see Spyder relaunch with the Spyder Light Syntax Highlighting Theme: You can return to Preferences and change the Editor settings. For beginners it is recommended to Show Blank Spaces and Indent Guides as spacing within Python is important: ### Script Editor and Kite Autocompletion To the left hand side is the Spyder script Editor. This can be used to write a script and has a tabbed interface so you can work with multiple script files: To save your script file, select File → Save As… Then select your file location (the convention is to use folders that have lower case folder names without spaces): Then rename the Python Script File, the convention is to use lower case names without spaces for script files, note that the .py extension will be added automatically: Now the Address Bar and the name of the tab reflect the file path of the script file and the name of the script file respectively: When you type in the script editor, Kite Autocompletion will pop up displaying suggestions: When a library is imported, items from it can be accessed by typing the library name followed by the dot . syntax. A Kite dropdown list pop up will display of the objects: For a function or class, details about the input arguments will be shown when the function or class is typed with open parenthesis as a pop up: Auto-completion should work for the most commonly used datascience libraries such as numpy, matplotlib and pandas if using Spyder 5.1.5 (Spyder 5.0.5 had an issue which slowed the autocompletion down): ### Help Pane Tab Some classes or functions have a tool tips which can be expanded in the Help Pane: Objects can also be highlighted in the script editor and the shortcut key [Ctrl] + [ i ] can be pressed to inspect their documentation. This opens in the Help Pane. ### Run Settings and Cells We can create a very basic script which will print the str "Hello World" to the console: print("Hello World") When the first script is run, the run settings dialog will display. I will leave all these settings at default and select Run. These settings can later be changed by selecting Preferences and then Run: You will see the print statement, printed to the console: Beside the Run Button, is the Run Cell Button. The popup dialog informs us that we can create new cells using #%%: We can create a script with cells using: #%% Cell 1 print("Hello World") #%% Cell 2 print("Goodbye Cruel World")  Note the currently selected cell is highlighted in yellow. The run cell button rns the currently selected cell and this cell is still highlighted after the cell is ran: The button beside this, runs the currently selected cell and then moves onto the next cell: The button to the right of this is the Run Selection button: This is the equivalent of running a single line in the console. ### Variable Explorer Tab Spyder has a Variable Explorer which makes it easy to visualise data. The variable name, type, size and value are shown. Different datatypes are colour-coded. For collections such as list, dict, numpy arrays and DataFrame, the variables can be expanded and visualised in more details: #%% Imports import numpy as np import pandas as pd #%% Create Variables (Builtin Python) a = "Hello" b = 1 c = 2.1 d = True e = [1, 2, 3, 4, 5] f = {"fruit": ["apple", "banana", "pear"], "quantity": [2, 2, 1], "calories_per_unit": [52, 89, 57]} #%% Create Variables (Datascience Libraries) g = np.array(e) h = pd.DataFrame(f) ### Files Tab A basic Excel SpreadSheet Book1.xlsx can be saved into the same folder as the Python Script spyder_test.py: The Current Working Directory is the folder where the last script run is stored. In this case, the Excel SpreadSheet and the Python Script show in the Files Tab: We can use the pandas function read_excel to read this Excel File into a DataFrame because it is in the same folder as the script file i.e. relative to the script file, we only need to specify the file name and not the full file path: #%% Imports import numpy as np import pandas as pd #%% Create Variables (Builtin Python) a = "Hello" b = 1 c = 2.1 d = True e = [1, 2, 3, 4, 5] f = {"fruit": ["apple", "banana", "pear"], "quantity": [2, 2, 1], "calories_per_unit": [52, 89, 57]} #%% Create Variables (Datascience Libraries) g = np.array(e) h = pd.DataFrame(f) #%% Read xlsx File i = pd.read_excel("Book1.xlsx") ### Plots Tab and Plot Settings We can use the plot function within the matplotlib pyplot module to create a plot: #%% Imports import numpy as np import pandas as pd import matplotlib.pyplot as plt #%% Create Variables (Builtin Python) a = "Hello" b = 1 c = 2.1 d = True e = [1, 2, 3, 4, 5] f = {"fruit": ["apple", "banana", "pear"], "quantity": [2, 2, 1], "calories_per_unit": [52, 89, 57]} #%% Create Variables (Datascience Libraries) g = np.array(e) h = pd.DataFrame(f) #%% Read xlsx File i = pd.read_excel("Book1.xlsx") plt.plot(i.x, i.y) By default it displays as an inline plot (static plot) in the Plots tab: We can also use interactive plots which have their own dedicated plot window. To get automatic plots, select Tools → Preferences: To the left hand side select Ipython Console and to the top select Graphics. Then change the Backend to Automatic. Then select Apply: For changes to take place, the Kernel needs to be restarted. Select Consoles → Restart Kernel. This will clear all Variables and close all imported modules: Select Yes: Plots in the plots pane will remain but can be removed: Now when the script is ran, the plot displays as an Automatic Plot and has its own dedicated Window: ## JupyterLab IDE The JupyterLab IDE is browser based and the Notebook format within JupyterLab has some advantages over the script files used in Spyder as it includes the markdown syntax which essentially allows one to create a Notebook with executable code. In other cases, this Notebook format is a disadvantage over writing pure Python code in Spyder using script files for example in the creation of a script for an automated process or a Python module. ### Launching JupyterLab The JupyterLab IDE has no Start Menu shortcut and must be launched either from its tile within the Anaconda Navigator or via a command line in the Anaconda Powershell Prompt. To launch jupyterlab we use the command: jupyter-lab Note the dash – which doesn't get used when using the conda install, search, update commands. ### JupyterLab File Explorer To the left hand side is the JupyterLab file explorer. This can be used to select a folder and open a file. Alternatively one can right click an empty space to create a new folder or right click a folder/file to rename them. To the top left is the launcher. A launcher is already open by default and can be used to create a new Text File, Markdown File or Notebook File. Additional launchers can be opened in separate tabs to work with multiple files simultaneously. We can right click the file (or the tab name) and select rename: In this example the file is renamed and the updated file name shows in the opened tab: The File Menu has the usual save options. If we go to the File Explorer in Windows 11, we will see that our text file exists and can be opened in Notepad. All of the files which we will save will display within Windows Explorer but to open them we will usually launch JupyterLab and use the JupyterLab file explorer to open the file opposed to the Windows 11 File Explorer (which won't find a program to open the file extension). ### JupyterLab Markdown File It is fast to write text to a text file but we have next to no formatting capability. The markdown file allows us to intuitively create a file with some basic formatting. We can launch a new Launcher and then create a New Markdown File and rename it, just like we did with the text file: We can right click some blank space in the Markdown file and view the Markdown Preview: #### Headings We can prefix text with # to create a Heading. The number of # we prepend, assigns the level of Headings: # Heading 1 ## Heading 2 ### Heading 3 #### Heading 4 JupyterLab has a navigation pane and the headings will auto-populate this as they are created. #### Formatted Text The * can be used to enclose text. Enclosure by a single * makes the text italic, enclosure by two * makes the text bold and enclosure by three * makes the text bold-italic. Enclosure by two ~~ makes the text strike-through. Let's make a sentence with *italic text*, **bold text**, ***bold-italic*** and ~~strike-through~~ text. #### Spacing Text on a new line will automatically be joined together with text on the line before to form a paragraph. She sells seashells on the seashore To explicitly specify text output on a new line, we need to use a blank line: She sells seashells on the seashore #### Lists Bullet Point List: * one * two * three Bullet Point List (spaced): * one * two * three Numeric List: 1. one 2. two 3. three Numeric List (spaced): 1. one 2. two 3. three  #### Tables We can use the pipe to create a table, row by row. The first row is the column names and the second row is the column formats (which can be changed to normal, left aligned, right aligned, left-aligned with title centred): |num|number| |---|---| |1|one| |2|two| |3|three| |num|number| |---|:-| |1|one| |2|two| |3|three| |num|number| |---|-:| |1|one| |2|two| |3|three| |num|number| |---|:-:| |1|one| |2|two| |3|three| We use square brackets to enclose a link text, followed by parenthesis to enclose a link: [Anaconda Individual Edition](https://www.anaconda.com/products/individual) The link can be to an image: [Anaconda Logo](https://www.anaconda.com/imager/assetsdo/Content/individual-edition-2021-05/47600/AIE-2021-Navigator_69c3a6a2ae8373ad29ab2c2b8be2395d.png) We can display an image within the markdown file by prepending it with an exclamation mark: ![Anaconda Logo](https://www.anaconda.com/imager/assetsdo/Content/individual-edition-2021-05/47600/AIE-2021-Navigator_69c3a6a2ae8373ad29ab2c2b8be2395d.png) If the image file is stored locally on your computer, you can use the file path of the image. Image files in the same folder as the Notebook file can be specified directly without the full file path. #### Code Three back quotes can be used to enclose an inline piece of code. They can also be used to create a code block: The first line of code is "Hello World". The code block is:  print("Hello World") print("Goodbye World")  It prints. #### Equations Inline equations are enclosed in a single and display equations are enclosed in a double $. The equations themselves must be written in LaTeX. This guide will use the Microsoft Word Equation Editor to copy an equation to LaTeX to use as an example: The equation is$f\left(x\right)=a_0+\sum_{n=1}^{\infty}\left(a_n\cos{\frac{n\pi x}{L}}+b_n\sin{\frac{n\pi x}{L}}\right)$The equation is: $$f\left(x\right)=a_0+\sum_{n=1}^{\infty}\left(a_n\cos{\frac{n\pi x}{L}}+b_n\sin{\frac{n\pi x}{L}}\right)$$ #### Escape Characters We have used #, *, ~, |, ,$ characters for format specification. If we want to include one of these as part of our markdown text, we need to insert them as an escape character. To do this we prepend the escape character with \ and when \ is the escape character to be inserted we use \\.

To make text bold we use \***bold**\*.

To insert a backslash we use \\.

### JupyterLab Notebook File

Now that we have an overview of markdown we can now create a JupyterLab notebook file and rename it as we seen before with the text file and markdown file.

Unlike Spyder where the use of Code Cells were optional, in a JupyterLab notebook file Cells are mandatory. Each Cell can be ran as either a Code Cell or Markdown Cell. For example the code we ran in Spyder before can be included in a Notebook:

# Python Notes
Importing the DataScience Libraries.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Inbuilt Example DataTypes
You should know:

* str
* int
* float
* bool
* list
* dict
a = "Hello"
b = 1
c = 2.1
d = True
e = [1, 2, 3, 4, 5]
f = {"fruit": ["apple", "banana", "pear"],
"quantity": [2, 2, 1],
"calories_per_unit": [52, 89, 57]}

In JupyterLab by default, each Cell is configured to be a Code Cell. The currently selected cell will be indicated in blue to the left hand side. To the top we can select the Cell Type dropdown list and change the Cell Type to a Markdown Cell:

Notice the change in the Syntax highlighting which makes the Cell look more similar to the Markdown text shown in the .md file:

### Cell Output

Instead of a separate Markdown Preview we Run each Cell. When we run a Markdown Cell it displays in an equivalent manner to the Markdown Preview.

Note that double clicking on the displayed Markdown Text will revert it back to a Markdown Cell which you can modify and Run again.

When we run a Code Cell we Execute the Code (similar to the way we ran a Cell within Spyder). The number which displays to the left hand side of the Code Cell indicates the order each Cell is Run and is equivalent to the number in the Prompt in the Spyder Console. Note that the number will increment each time a Cell is Run and Cells do not need to be Run in order. If a Cell is Run again only the most recent number will display to the left hand side:

Instead of having a Console, each Code Cell has a Cell output.

#### Variables

When a value is not assigned to a variable it will be output at the bottom of the Cell:

1 + 2

When a value is assigned to a variable it will not be output at the bottom of the cell (unless the print statement is used):

b = 1 + 2

#### Docstrings

The Docstring of a function or class can be output to a cell using the question mark before typing in the function or class name:

? round

For long Docstrings, the Cell Output can be converted to a scrolling output by right clicking the cell output.

#### Plots

We can access a file stored in the same location as the Notebook File. For convenience we will copy the Excell File we created before to this location:

i = pd.read_excel("Book1.xlsx")

We can create a plot of the DataFrame i:

plt.plot(i.x, i.y)

It will display as an inline plot by default:

We can change the plot backend to automatic, to instead plot the plot in a dedicated Window:

%matplotlib auto

Rerunning the Code Cell that creates the plot will update the Cell Output to inform you that the plot is Automatic and this plot will display in a seperate Window:

Notice that the Number of the Prompt to the left hand has now be updated from 7 to 9, so we can easily tell that this Code Block has been Run after the Setting for Automatic Plotting was applied. To change the backend back to inline use:

%matplotlib inline

We can left click the side of the Code Block beside the [8] and if we hold down the left click we can drag it to reposition it:

For example we can update the Notebook to specify the matplotlib backend immediately after importing matplotlib near the top of the Notebook:

### Useful Shortcut Keys

#### Changing Cell Type

[Esc] + [ m ] will change the currently selected Cell Type from a default Code Cell to a Markdown Cell.

#### Running Cells

There are two shortcut keys to Run a Cell.

[Shift] + [Enter] will run a Cell and move onto the next Cell:

[Alt] + [Enter] will Run the Cell and select a blank Cell below it:

#### Code Autocompletion

In order to see the list of available objects that can be called from a module or a class (which we can think of as a container). We have to type in dot . (to look in the container) and then we can type in [Tab] to view a dropdown of objects within the module or class (a list of all the items within the container):

We can also type in a function or class with open parenthesis followed by a [Shift] and [Tab] to view the Docstring as a pop up balloon to quickly view details about the input arguments:

## JupyterLab Lab Extensions

JupyterLab Lab Extensions can be used to increase the functionality of JupyterLab. Lab Extensions are made by third party developers and unfortunately at present can be a bit problematic and lead to a situation where JupyterLab does not work correctly…

### jupyter labextension command

JupyterLab is supposed to have a labextension command which is used for installing extensions when JupyterLab is used outwith a conda environment. Like pip (Python install package), the labextension command is recognised by the Anaconda Powershell Prompt but can be problematic and should be avoided in preference for a conda install command equivalent where possible:

jupyter labextension install @name-of-repository/name-of-extension

It normally results in an issue when it comes to building JupyterLab resulting in the extension being disabled making it unusable.

As a consequence the most commonly used extensions have been uploaded to the conda-forge repository and these install correctly with the Anaconda Powershell Prompt.

jupyter lab build

These conda install instructions are unfortunately not mentioned on the GitHub page however you can search conda website for more details:

### Creating a conda environment for jupyterlab and lab extensions

We will use similar commands to create a new conda environment for the latest version of JupyterLab and JupyterLab extensions. These commands are similar to the ones we used when doing the same with Spyder.

conda create -n jupyterlab3114
conda activate jupyterlab3114
conda config --set channel_priority strict
conda install jupyterlab=3.1.14
conda install cython matplotlib numpy pandas scipy sympy seaborn openpyxl
conda install nodejs ipywidgets jupyterlab-variableinspector ipympl plotly jupyterlab-drawio
jupyter-lab

More details about these extensions are as follows.

### nodejs

JupyterLab Lab Extensions use the nodejs framework. The latest version of this should be installed before installing any extension.

This widget now comes preinstalled as part of JupyterLab, you should not follow any instructions on older guides to attempt to install it.

### Interactive Python Widgets

The interactive Python widgets (ipywidgets) are preinstalled with Anaconda. These can be used for the creation of interactive sliders and displays.

### Variable Inspector

JupyterLab by default is sadly missing the Variable Explorer exhibited within the Spyder IDE. The JupyterLab Variable Inspector is an extension that gives JupyterLab a basic equivalent:

Once enabled you can right click on a blank space within the Notebook and select Open Variable Inspector:

The Variable Inspector will open in a new tab:

However you can drag and drop the tab to change the layout:

The Variable Inspector just lets you view the Variables, it does not allow you to fully interactively Explore them like the Spyder Variable Explorer:

### Interactive Python matplotlib

Earlier we seen we could either have a dedicated interactive plot within its own Windows or a static plot nested within the cell output of the notebook using the matplotlib backends automatic and inline respectively.

The interactive Python matplotlib (ipympl) notebook extension can be used for an additional matplotlib backend called widget which nests the plot interactively within the notebook:

### plotly

The plotly extension can also be used allowing for browser based interactive plots using the plotly library. For instalaltion plotly have their own channel called plotly.

More details and the test code above can be seen on the getting started guide on the plotly website:

### draw.io

The draw.io extension adds a diagram tab to the launcher. You can use draw.io to draw a diagram. Unfortunately it does not include support for draw.io files within a JupyterLab notebook so you will have to convert the draw.io diagram file into an image in order to display it within a JupyterLab Notebook:

## Windows Terminal and Windows Environmental Variables Path

### Windows Environmental Variable Path

During installation of Anaconda, you will get the option to "Add Anaconda3 to my PATH environmental variable":

This means you should be able to right click your Start Button and select Windows Terminal:

And the commands python, conda, spyder and jupyter-lab should all be recognised within the Windows Terminal. For example:

python --version

If you get a Python not found error, it wasn't added to the Windows Environment Path during installation and needs to be manually added (see below).

If a folder is created within Documents called windows_terminal_test. We can select this in the terminal by using:

cd Documents
cd windows_terminal_test

We can create a python test file in notepad called test_script.py (note the .py extension and not the default .txt extension). To run this test script in the terminal we can type:

python test_script.py`

As well as using Python we should be able to use any of the Python libraries installed within our base conda environment:

While the Windows Terminal looks at first glance a lot like the Anaconda PowerShell Prompt note the omission of (base) to the left hand side. The Windows Terminal uses the conda environment specified in the Windows Environmental Variables Path and the command conda activate command does not change this so this command essentially does not work within the Windows Terminal.

To view the Windows Environmental Path, we can right click the Start Button and select Settings:

Then to the left hand side, select System and scroll down to the bottom and select About: