Miniconda is an Anaconda based installer, which has a lightweight base Python environment instead of a data science distribution. This base Python environment contains Python 3.11 and the conda package manager which can be used to create Python environments. The conda-libmamba-solver is included with Miniconda which greatly increases its performance.
The conda package manager has two channels:
- conda: default
- conda-forge: community channel
The conda-forge channel is the community channel and is maintained directly by project developers. The conda channel is a channel maintained by anaconda developers who test packages for compatibility with their Anaconda Python Distribution. As it takes time to test packages and they only test more popular packages, this channel is usually behind the community conda-forge channel. It is generally more reliable to use the conda-forge channel when creating custom environments.
Unfortunately neither the conda-forge channel or conda-libmamba-solver are enabled by default but can easily be enabled post-installation by a .condarc configuration file.
Miniforge and Mambaforge were modified Miniconda installers that are defaulted to the conda-forge channel and in the case of Mambaforge included the mamba package manager. These installers are outdated on Windows (have old Python versions) and lack some features (using the depreciated CMD instead of PowerShell).
Miniconda may not work as intended when another Anaconda based Python distribution is installed such as Anaconda, Miniconda (including Miniforge, Miniconda).
If you have an old Python installation follow the instructions to Uninstall and Purge old Python Distributions. This will allow Miniconda to be installed properly.
The download link for Miniconda can be found on the Miniconda home page. Select Miniconda3-Windows-64_bit:
The setup should now be in the Downloads folder:
Launch the setup:
The setup will begin:
Accept the License Agreement:
Select just me (recommended):
The default install location will be in:
The environmental variable %USERPROFILE% maps to the location of your User Profile, in this case C:\Users\Philip
Installation options will display:
A common option the I recommend enabling (although shown as not recommended) is to add Miniconda to the Windows Environmental Variables Path which makes the (base) Python environment available in the Windows Terminal.
Note that leaving this option unchecked may cause a minor issue with VSCode. VSCode uses the Windows Terminal and shows an error message when launching a Python script when the (base) Python environment is not added to the path. If this option has not been checked, Miniconda can be manually added to the Windows Environmental Variables path see:
Adding Miniconda to the Windows Environmental Variables Path.
The reason this option is not recommended by default is it can arise to conflicts when multiple Python distributions are installed/uninstalled. In general it is not recommended to install multiple Python distributions and a better practice to stick to only using Miniconda.
Exploring the base Python Environment
Miniconda should be installed in:
In this folder is a python.exe
And a Lib subfolder:
This Lib subfolder contains Python standard modules.
These can be in the form of packages and the folder name is essentially the package name. For example in the case of email:
In the email folder is a __init__.py which is the initialisation module of the folder:
Or in the form of a module.py for example datetime.py
Miniconda PowerShell Prompt
The Miniconda PowerShell Prompt is a Windows PowerShell Prompt that also has access to the conda package manager and supports switching between Python environments:
This opens a Terminal similar to the Windows Terminal.
(base) indicates that the Miniconda Python base environment is selected.
C:\Users\Philip indicates the file path which is
%UserProfile% by default.
> indicates a new prompt.
The programming language used by the Miniconda Prompt by default is PowerShell. PowerShell is a scripting language that is essentially a terminal based equivalent of Windows Explorer. It is used essentially to navigate around the Operating System.
PowerShell uses a syntax of the form:
command option -p parametervalue1 command option --parametername2 parametervalue2 command option --parametername3
Whereas Python uses the following syntax:
The Miniconda PowerShell Prompt can be used to invoke Python from the (base) Python environment using:
Details about the Python version in (base) will display. Notice the prompt change from
> (PowerShell) to
The email package can be imported and the file of its intialisation module viewed using:
import email email.__file__
The datetime module can be imported and its file viewed using:
import datetime datetime.__file__
To exit Python the function:
can be used. Notice the prompt returns to
> indicating PowerShell.
To exit PowerShell use the command:
Notice the differences in the two syntaxes as the two different programming languages are used.
Python uses parenthesis to call functions and enclose any function input arguments. PowerShell, instead uses a space between the command and its input arguments. Do not confuse the two programming languages!
Third-party packages are in the site-packages subfolder
In the (base) Python environment this includes the conda package manager:
The packages can be viewed by inputting:
The PowerShell command cls can be used to clear the screen:
Configuring Channels and Solver
The Miniconda PowerShell Prompt opens in %USERPROFILE% by default:
This location can be viewed in Windows Explorer:
A .condarc file can be created in this location to configure to conda-forge select conda-forge as the default channel with a strict channel priority and to use the libmamba solver:
conda config --add channels conda-forge conda config --set solver libmamba conda config --set channel_priority strict
This updates the .condarc file:
This can be seen by opening it in notepad using:
This has the form:
channels: - conda-forge - defaults solver: libmamba channel_priority: strict
Updating the (base) Python Distribution
THIS COMMAND SHOULD NEVER BE USED WITH THE ANACONDA PYTHON DISTRIBUTION AS IT WILL LEAD TO AN UNSTABLE BASE PYTHON ENVIRONMENT EFFECTIVELY PURGING THE DATA SCIENCE DISTRIBUTION.
The conda package manager in the Anaconda base distribution can be used as is to make Python environments. The base Python environment should only be updated via a standalone installer when made available (usually bi-annually by Anaconda).
The PowerShell command conda can be used with option and named parameter –all to update all packages:
conda update --all
This will update all packages in the base Python environment.
Notice that this switches the channel from conda to conda-forge for all packages in the base Python environment. Input
y to proceed:
The base Python environment is now ready:
And the changes can be seen in Windows Explorer:
More details can be sen using:
Useful PowerShell Commands
The most commonly used PowerShell commands are:
|cls||Clears the Screen|
|mkdir||Make a Directory|
|rmdir||Removes a Directory|
|type||Displays the contents of a text file|
PowerShell can also be used to launch Windows Applications for example:
The Miniconda (base) environment also includes:
|conda||conda package manager|
If other IDEs are installed:
|jupyter lab||Launches JupyterLab (lab gives the option lab)|
|jupyter||Launches Jupyter Notebook (legacy)|
The Miniconda Prompt opens in the environmental variable
%USERPROFILE% by default which in my case is
Documents is a subfolder and the directory can be changed to Documents using:
~ is a shortcut to the Windows Environmental Variable
../ mean in the same folder as and up a level respectively:
To clear the screen use:
A new Python script file can be created in PowerShell using:
To list all directories and files use:
This can be opened in notepad using:
The following Python code can be added to the script file using notepad:
The Python script file can be ran using:
If the code in the script file is changed to:
import time time.sleep(5000)
The console will hang for 5000 seconds while running the script file:
The keyboard shortcut
c is used to close an operation that is running in terminal.
To copy from the terminal the keyboard shortcut
c is used.
To paste to the terminal the keyboard shortcut
p is used.