This guide looks at installing Anaconda 2024-02.1 on Windows 11.
Removing Previous Installations¶
Anaconda should be installed on a Linux PC that has no previous Python installations outwith the system Python. The system Python is preinstalled as part of the Linux Operating system and should be considered as part of the Operating System and not modified by the user.
If an old Anaconda Installation or an Anaconda based installation such as Miniconda or is present these should be removed by deleting their perspective folders. Note that deletion of these folders leaves behind a large number of configuration files and the presence of these files often results in problematic settings persisting after a reinstall. For best results it is recommended to delete all these configuration files. For more details see Uninstallation Instructions.
Anaconda vs Miniconda¶
Anaconda is a Python distribution that has a base Python environment that is designed to be used as is. The base Python environment has the conda package manager that can be used to create a separate Python environment (subinstallation of Python) for a custom configuration of packages.
Miniconda is a bootstrap version of Anaconda, that only contains the conda package manager and can likewise be used to create Python environments.
Anaconda should be preferenced when, the user required a preconfigured (base) Python environment to be used as is. When the user plans to only create custom Python environments, Miniconda should be preferenced.
Anaconda Python Distribution¶
The Anaconda Python distribution comes with its own base Python environment that contains:
- Python
- Python Standard Libraries
- The conda Package Manager
- The Anaconda Navigator
- Third Party Libraries:
- numpy
- pandas
- matplotlib
- seaborn
- plotly
- pillow
- scikit-learn
- scikit-image
- ⁝
- Third-party IDEs:
- Spyder
- Jupyter
- JupyterLab
- Jupyter Notebook
- Jupyter QTConsole
- Jupyter Console
- Third-party formatters:
- autopep8
- isort
- black
Miniconda¶
Miniconda is a stripped down version of Anaconda containing only:
- Python
- Python Standard Libraries
- The conda Package Manager
conda¶
Anaconda and Miniconda have the conda package manager which should be used in preference to the native Python package manager pip.
- conda
pip
pip is strictly a package manager for Python packages. However many datascience projects under the hood, use code that is written in C++ for performance gains. The conda package manager manages both the Python and non-Python dependencies. The conda package manager has also been written in C++ for increased performance and reliability. This was separately developed as mamba and the conda package manager uses the libmamba (C++) solver by default.
The conda package manager uses two channels:
- conda-forge
- anaconda
The first channel community forge is the community channel and has the largest number of packages available.
The second channel is the channel maintained by Anaconda Inc. Anaconda Inc test packages for compatibility with the Anaconda Python Distribution.
As a consequence the latest version of a package available on the anaconda channel may be dated with respect to the package on the conda-forge channel as it takes Anaconda Inc some time to test packages. Moreover Anaconda Inc only test the most commonly used datascience libraries and therefore more niche packages will only be available on conda-forge.
In the Anaconda base environment the following commands should never be used:
pip install packageconda install conda-forge::packageconda install -c conda-forge package
This is because use of multiple package managers and use of multiple channels will make the Anaconda base Python environment unstable.
Only packages available from the anaconda channel should be installed in base:
- conda install anaconda::package
- conda install -c anaconda package
The base Python environment is normally used as is and instead a custom Python environment is used to install a subinstallation of Python with custom packages, usually from the conda-forge community channel. More details about channels will be given later.
Download Links¶
The latest Anaconda and Miniconda installer can be downloaded from:
Using Anaconda as an example, Windows 11 can be selected:
Select the 64 Bit Graphical Installer:
The download will be save in Downloads by default:
Install¶
Double click it to launch the installer:
Select Next:
Then I Agree:
Anaconda should be installed for a single user. Select Just Me (recommended) and then Next:
The default install location is a subfolder of the user profile:
This is accessed in Windows Explorer using the environmental variable:
%USERPROFILE%
If the Start button is right clicked and the Terminal launched:
The Terminal opens in the default location which is the User Profile:
In the Terminal, the User Profile can be accessed using:
~
Select Next:
Use the default options and select Install:
Select Next:
Select Next:
Select Finish:
Python¶
Anaconda or Miniconda are installed in
%USERPROFILE%\anaconda3
%USERPROFILE%\miniconda3
This folder contains the base python.exe
:
In the Start Menu, there is an Anaconda3 folder, there are two shells:
- Anaconda PowerShell Prompt
Anaconda CMD Prompt
This is because Windows has two shells, the modern PowerShell and legacy CMD. PowerShell is more feature rich and should be preferentially used:
The Anaconda PowerShell Prompt has (base)
as a prefix which means it will look in the locations associated with the base Python environment for an application. The python.exe
for example can be run. Note the .exe
file extension is not typically specified so it is run using:
python
The Windows Terminal is not initialised and does not look in the base Python environment:
It therefore cannot find the python.exe
and prompts for installation of a system Python via the Microsoft Store. This shouldn't be installed as it'll create confusion.
The python.exe
from base can be used by specifying the full path:
~\anaconda3\python
Python Libraries¶
The python installation has an associated:
~\anaconda3\Lib
folder where Python Libraries are stored.
This contains the standard libraries such as email:
Note that this folder has a datamodel initialisation file __init__.py
which is reference when the module is imported.
Note Windows uses \
as a path separator and Python also uses \
to insert an escape character into a str
. Therefore \\
gives an instruction to \
itself as an escape character. When the str
is printed, the escape characters are processed:
Other standard modules are individual modules, such as datetime. These are referenced when these modules are imported:
Third-party libraries are found in the subfolder
~\anaconda3\Lib\site-packages
Anaconda has the most commonly used datascience libraries such as numpy (Miniconda doesn't have this library preinstalled). There is a folder for a library and another folder which details the version number:
The __init__.py
file is reference when this library is imported, using the alias np
:
numpy is a very large library and has submodules, the submodule random can also be imported:
Notice it has its own associated __init__.py
file:
This file is referenced when this module is used:
So far the Anaconda PowerShell Prompt has been used which as the name suggests uses PowerShell by default as a programming language. This has been used to run a Python Shell.
All the code in the highlighted selection is Python code and has the prompt >>>
. The code outside the highlighted selection has a prompt (base) PS ~>
where PS means PowerShell:
conda Package Manager¶
Other applications associated with the base Python environment are found in the
~\anaconda3\Scripts
folder.
This has the conda
package manager:
The Anaconda PowerShell Prompt can be cleared using:
clear
The conda
package manager can be used:
conda
And an output of commands recognised by this application are listed:
Updating¶
The conda
package manager is updated approximately monthly to address bugfixes with newer packages and should be updated to the newest version on Anaconda or Miniconda using:
conda update conda
The channel used shows defaults which is the anaconda
channel and this is the only channel that should be used for base. Using another channel here will create an unstable base Python environment.
Updating the conda package manager on Anaconda will usually update some other components in the remaining Python distribution.
In this case, conda is already updated updated as the standalone installers have just been released:
On Anaconda, the Anaconda Navigator is updated separately, so it can be independently updated when using the Anaconda Navigator GUI. It is normally more reliable to update it using:
conda update anaconda-navigator
Input y
to proceed with any changes:
The Anaconda Navigator is now updated:
MikTeX¶
Anaconda doesn't contain all the TeX fonts which are required when exporting a notebook with TeX or creating a plot with TeX.
They can be installed using MikTex which can be downloaded from:
Select Download:
When the Download is complete:
Launch the GUI installer:
Accept the License Agreement and select Next:
MikTeX should be installed for a single user. Select the default Install MikTeX Only for Me and select Next:
MikTeX is installed within a subfolder of Local Appdata:
This is a special location and has the environmental variable:
%LOCALAPPDATA%
Use the default install location and select Next:
Select the default settings and select Next:
Select Start:
Select Next:
Uncheck Check for Updates Now and select Next:
Select Close:
If the Start button is right clicked and System selected:
The Advanced System Settings:
And Environmental Variables can be examined:
The Windows Path contains the locations the Windows Terminal looks for applications. Select Edit to view it in more detail:
Notice the entry for MikTeX can be seen:
The Windows Terminal will examine the entries in the path when launched. Any open Terminals will have to be closed and reopened.
This can be opened in the file explorer:
%LOCALAPPDATA%\Programs\MikTeX\miktex\bin\x64\
In this folder are a number of applications such as the miktex-console
:
This can be launched in the Windows Terminal by using:
miktex
Go to the Updates tab. Select Check for Updates:
Select Update Now:
Select OK when prompted to close the MikTeX Console:
Launch the MikTex Console again:
miktex-console
Go to the Packages tab and sort by Installed On:
Highlight the first package without an Installed on date and hold down ⇧
:
Then scroll down to the bottom which will highlight all uninstalled packages. Select + to install these:
Select OK:
These may take a while to download. Close the MikTeX console when it has finished:
Initialising¶
When Anaconda/Miniconda are installed. The option to add the base Python environment to the Windows Environmental Variables Path is not recommended, as this locks the Windows Terminal to a single Python Environment:
The Windows Terminal can be initialised, which makes it behave equivalently to the Anaconda PowerShell Prompt, allowing use of multiple Python environments. Right click the Start button and select Terminal (Admin):
Input the following commands:
Set-ExecutionPolicy RemoteSigned
For Anaconda input:
anaconda3\Scripts\conda init powershell
For Miniconda input:
miniconda3\Scripts\conda init powershell
Details about the file changes will be listed and there is an instruction to close any open shells:
Now when the Windows Terminal is launched:
It will display the prefix (base) and behave identically to the Anaconda PowerShell Prompt:
The command
python
now work as expected:
Anaconda Navigator¶
Returning to:
%USERPROFILE%\anaconda3\Sxcripts
The anaconda-navigator
is the Anaconda Navigator:
And can be launched from the Terminal using:
anaconda-navigator
This will display a splash logo and the Terminal will remain busy while the main event loop for the QTMainWindow is running:
The main window looks as follows and has a number of tiles which can be used to launch commonly used Python Shells or Integrated Development Environments (IDEs):
The applications preferences can be changed by going to File → Preferences:
Unfortunately the Enable High DPI Scaling setting often does not work and the preferences box is stretched off the screen making it impossible to click the close button, cancel button or apply button:
The Configure Navigator button is a means to configure the Anaconda Navigator settings programmatically:
The Configure Conda button is a means to configure the conda package manager recall parameters programmatically. It is recommended to leave these settings at the defaults which essentially means the default channel used is the anaconda
channel and means the right channel is used when working with the base Python environment:
As the Preferences window cannot be sued when it displays offscreen, the two files above can be modified using notepad. For the Anaconda Navigator, open up file explorer and go to:
%APPDATA%
Select the .anaconda
folder:
Select the navigator
folder:
Open the anaconda-navigator
file in notepad:
Change enable_high_dpi_scaling
to False
. Then close the Anaconda Navigator and relaunch it:
For the conda package manager, go to:
%USERPROFILE%
Open the .condarc
(conda recall parameters) file in notepad:
The settings should be at the defaults:
The Anaconda Navigator can be quit:
When it is closed, a new prompt should display. If the process is still hanging press Ctrl
+ c
to close the currently running operation:
IPython¶
Returning to:
%USERPROFILE%\anaconda3\Scripts
The Interactive Python shell can be found as ipython
or the alias ipython3
. In the past when Python Version 2 and 3 were installed, the 3 was used to distinguish versions. Now that Python 2 has reached end of life and is not installed, the alias without the 3 is typically used:
To launch ipython
open up the Terminal and input:
ipython
Notice that it looks very similar to the Python shell however there are some key differences. The prompt is now a numeric integer. In addition when ↹
is pressed after a prefix, a list of identifiers beginning with the prefix displays:
The identifiers beginning with %
are ipython magics and are commonly used shell commands, for example %conda
. The ipython magics allow use of commonly used shell commands within the ipython shell, without exiting the ipython shell.
On Windows the ipython magics use the legacy CMD instead of modern PowerShell. CMD is a subset of PowerShell.
A functions docstring can be viewed in the ipython cell output. The other main improvement over the Python shell is that syntax highlighting is applied making it easier to read the Python code:
The reason for preferencing CMD over PowerShell is due to the common prevalence of -
in a PowerShell commandlet for example Get-Alias
and Set-Location
because -
is recognised in Python code as the -
operator. The CMD commands are more similar to the names of the bash commands which is the shell language in Linux and are more concise and less likely to contain -
. It is recommended to use the commands with the %
prefix to highlight that they are ipython magics however they can be used without the %
prefix:
Jupyter¶
Jupyter is an abbreviation for Julia, Python et R. There are four main applications:
jupyter-console
jupyter-qtconsole
jupyter-notebook
jupyter-lab
The application jupyter
also accepts the command option:
jupyter console
jupyter qtconsole
jupyter notebook
jupyter lab
however it is more common to use each application directly.
The jupyter-kernelspec
application can be used with the command list
to list kernels. By default only a Python kernel is listed:
On Windows, Julia is not available as a conda-forge
package and must be installed system wide using the Windows package manager winget using the following command:
winget install julia -s msstore
Unfortunately, winget is not available by default on Windows 11, unless the Windows Store is opened, the library selected and Get Updates selected:
The command can then be used to install Julia:
The system Julia can be accessed by inputting:
julia
For Julia, the Julia package manager Pkg should be used to add the interactive Julia kernel:
using Pkg
Pkg.add("IJulia")
The Julia application can then be exited:
exit()
Now using:
jupyter-kernelspec list
lists both julia-1.10 and python3 as kernels:
When the application:
jupyter-console
is launched, it uses the default kernel python3 and behaves essentially identical to ipython:
The --kernel
option can be added to select a different kernel:
jupyter-console --kernelspec=julia-1.10
Note the exit
command will only exit the ijulia cell, to exit Julia, press Ctrl
+ d
:
Input y
to proceed:
The conda-forge community channel has wide support for Python and R. Although Python and R each have their own perspective package managers, they should not be used in a conda environment. Instead conda should be used to install any packages.
Packages from the conda-forge community channel should not be installed in the base Python environment as it will make the base Python environment unstable.
Instead a new Python environment (Python subinstallation) should be created:
conda create -n jupyter-env -c conda-forge python jupyterlab jupyter cython seaborn scikit-learn pyarrow sympy openpyxl xlrd xlsxwriter lxml sqlalchemy tabulate nodejs ipywidgets plotly pyqt isort autopep8 ruff black ipympl jupyterlab-variableinspector jupyterlab-variableinspector jupyterlab_code_formatter jupyterlab-spellchecker r-irkernel jupyter-lsp-r r-tidyverse r-ggthemes r-palmerpenguins r-writexl
Note the specification of the -n
(--name
) which instructs the current operation to install packages into the Python environment jupyter-env
opposed to the Python environment (base)
.
Note the specification of the -c
(--channel
) which instructs the current operation to preferentially install packages from the community channel and is seen in the channels list below.
The conda package manager, now that it has the modern libmamba solver by default will quickly solve the Python environment. It essentially checks the requirements for each library and solves a set of compatible versions:
The environment location is listed, which is jupyter-env
:
Details about the packages being downloaded, their version number, build number and channel are listed:
Input y
to proceed with the changes:
The Python environment will be created:
It will need to be activated to be used:
conda activate jupyter-env
Notice the prefix is now (jupyter-env) which mean the python application and its associated libraries and applications are preferentially used over their counterparts in base.
Now when:
jupyter-kernelspec list
is used, the three kernels julia-1.10, python3 and ir show:
The R kernel can be selected using:
jupyter-console --kernel=ir
The Python environment can be deactivated using:
conda deactivate
This returns to (base). (base) will remain the default Python environment for any new Terminal instances.
Julia and R can be used in the remaining Jupyter applications. However these tutorials will stick only to Python.
The Jupyter QTConsole is essentially a rewrite of the Windows Terminal using the QT GUI framework.
It can be launched using:
jupyter-qtconsole
The Terminal remains while the QTMainWindow is open:
Rewriting the Terminal using QT allows the docstring to automatically populate as a popup balloon:
It also allows the nesting of graphics:
The output can be saved to a HTML file which is essentially a read only website. Select File → Save to HTML:
Go to your Documents folder and save the file as ipython.html
:
Select Inline:
This HTML file shows as a website and can eb opened in a browser:
The QTConsole can be Quit:
This should close the QTMainWindow and show the next prompt in the Terminal. If not press Ctrl
+ c
to cancel the currently running operation.
So far various shells have been examined. Typically an IDE is used for more serious code editing which contains a console, and a means to manipulate a file or notebook.
JupyterLab is a browser based IDE and can be launched using:
jupyter-lab
The Terminal runs a server and remains busy while the server is running. The visual elements display in the browser:
The JupyterLab IDE has a Files tab to the left which is a browser based implementation of File Explorer.
On Windows there are two Documents folders:
%USERPROFILE%\Documents
%USERPROFILE%\OneDrive\Documents
The Documents shortcut on Windows File Explorer maps to the first folder if Windows 11 is installed and setup without OneDrive integration.
The Documents shortcut on Windows File Explorer maps to the second folder if Windows 11 is installed and setup with OneDrive integration.
You should navigate to the correct folder corresponding to your setup:
To the right hand side is a launcher (a new tab begins a new launcher). The launcher can be used to create a new file, in this case a new Python 3 Notebook file:
The Files tab can be used to rename a file by right clicking and selecting Rename:
The notebook file consists of ipython cells and markdown cells which can be used to document the code:
To run a cell, use the run button or press the keyboard shortcut key ⇧
and ↵
. To run a cell and insert a blank one below use the keyboard shortcut key Alt
and ↵
.
To view a list of identifiers input ↹
after a prefix:
To view a docstring press ⇧
+ ↹
:
JupyterLab has a Variable Inspector, which can be accessed by right clicking the notebook file and selecting Open Variable Inspector:
The tab can be repositioned:
The table of contents can be selected which lists markdown headings and can be used to navigate through the notebook:
A plot can be added to the cell output:
The notebook can be saved, using File → Save Notebook. There is also the option to Save and Export the Notebook in various other outputs such as html and pdf:
When the browser is clsoed:
The JupyterLab server will remain running in the Terminal. To close it press Ctrl
+ c
:
A new prompt will display:
The notebook file can be viewed in File Explorer:
When opened in notebook it displays in json format. This is used by the JupyterLab server and the browser to display the visual elements:
Typically the notebook is not opened in Notepad. Instead JupyterLab is launched and the files tab is used to open the notebook. The notebooks kernel should also be restarted in order to continue editing the notebook.
Jupyter Notebook is a simplified version of JupyterLab.
Spyder¶
Returning to:
%USERPROFILE%\anaconda3\scripts
Another application is spyder
which is an abbreviation for the Scientific Python Development Environment:
Spyder is preinstalled in Anaconda. For Miniconda, a separate Python Environment can be created to install the latest version of Spyder using:
conda create -n spyder-env -c conda-forge python spyder cython seaborn scikit-learn pyarrow sympy openpyxl xlrd xlsxwriter lxml sqlalchemy tabulate pyqt ruff ghostscript
Spyder can be launched from the Terminal using:
spyder
This IDE has a script editor, that applies syntax highlighting, highlights syntax errors and has a number of tools to help improve code quality:
The Source menu has the Format File or Selection with AutoPEP8 option:
This will move imports to the top and address spacing issues:
The autoformatter can be changed using Tools → Preferences:
Selecting the Code and Linting tab to the left and then switching to black:
Now the Source menu has the Format File or Selection with Black option:
This applies blacks opinionated formatting. At current there are some limitations as black won't organise the imports correctly before applying opinionated formatting and so black does not work unless autopep8 has previously been used:
These options use the autopep
and black
applications found in the:
~\anaconda3\Scripts
folder. Spyder does not yet support isort
which is used to sort the imports alphabetically in two groupings (by standard module and third-party modules).
Unfortunately, blacks opinionated formatting differs from Pythons default representation and therefore many Python developers dislike black. A new project ruff is a faster implementation of black which can be configured to match Pythons default representation. Ruff is not yet integrated in Anaconda or Spyder.
Spyder has a very powerful Variable Explorer which can be used to visualise variables:
Identifiers corresponding to a prefix will display as a popup, alongside the associated docstring for a function:
The docstring can also be accessed by right clicking an object and selecting Inspect current object:
This will open up the documentation in the Help pane:
Plots are by default displayed as static images in the plots pane:
The plot preferences can be changed by going to Tools → Preferences:
Selecting the IPython Console tab to the left, the Graphics tab to the top right and changing the backend to Qt5 (Automatic is an alias for Qt5):
To apply the new preferences select Consoles → Restart Kernel:
Running the script will now display the plot in its own interactive window:
A comment can be added to a Python script file using #
. If #%%
is used, a new cell is created:
The script file can be saved using File → Save As…:
It can then be saved to the Documents folder:
The script file can be viewed in file explorer:
And opened in notepad but notice that no Syntax Highlighting or other visual aids from the IDE are provided:
When Spyder is closed, a new prompt will display. If it doesn't, press Ctrl
+ c
to close the currently running operation:
Environmental File¶
If the custom jupyter-env
is activated using:
conda activate jupyter-env
It can be exported to a yet another markdown language yml
file in the Documents folder using:
conda env export > ~\Documents\jupyter-env-file.yml
Or
conda env export > ~\Documents\OneDrive\jupyter-env-file.yml
Recalling that there are two Documents folders depending on whether the system has or doesn't have OneDrive integration:
This file can be viewd in File Explorer:
And opened in notepad:
Notice the env name, channels and each package alongside the package version and build number are shown:
In academic settings, an academic may issue a yml file which will reduce the liklihood of students encountering errors due to changes in newer versions of the libraries used.
If the environment is deleted using:
conda deactivate
conda env remove -n jupyter-env
The jupyter-env
specified in the jupyter-env-file.yml
file can be recreated using:
conda env create -f Documents\jupyter-env-file.yml
Or:
conda env create -f OneDrive\Documents\jupyter-env-file.yml
The environment is then recreated:
Updating an Environment¶
The conda
package manager can be used to update --all
packages to the latest version.
–all should never be used with base, instead the conda
package manager should be used to update conda
which will collectively update the distribution.
-c conda-forge should never be used with base, instead only the anaconda
channel (also known as the default channel) should be used.
The jupyter-env
can be updated using:
conda active jupyter-env
conda update -c conda-forge --all
Input y
in order to proceed:
Often with a complicated Python environments, better results are achieved by deleted the Python environment and recreating it with all packages specified during the time of creation.
Revision¶
The packages in a conda environment can be listed using the list
command:
conda list
The --revision
option can be used to list packages for each revision:
conda list --revision
The install
command can theoerically be used with the --revision
option to revert to a previous revision:
conda install -c conda-forge --revision=0
However the conda package manager, seems to hang for an extremely long time here for such a simple change. This command option will likely be optimized in a later version of conda. Unfortunately the conda env export command isn't configured to recognize --revision
as an option so it is recommended to export an environment out to a yml files before updating it.