Anaconda is an easy-to-install and free Python/R software distribution with a collection of 7,500+ open source packages (including R). When you install Anaconda, over 250 packages are automatically installed along with Python. If you do not want to have pre-installed packages, an alternative is to choose Miniconda that ships you only Python, conda (package&environment manager) and their dependencies.
Glossary:
System Requirement:
Anaconda Navigator is a desktop program that is bundled with Anaconda distribution. It provides a user-friendly interface for users to manage packages, environments and channels, without bothering to use terrifying command lines.
Windows Users: Start Menu -> find and click Anaconda Navigator(Anaconda3) icon.
Mac Users: Open LaunchPad and click Anaconda-Navigator icon.
The leftmost panel of Navigator shows the main things which you can do, that is,
Channel: is an online repository where Anaconda goes to to fetch packages. E.g., one of the biggest channel is conda-forge.
Environment is a mechanism used to create isolated package settings. You might have heard of "virtual environment" in Python community. Anaconda environment is essentially a replacement and upgrade to the virtualenv of Python, which offers more features and are easier to understand. It is is extremely useful when you manage multiple Python projects that have different package requirements. E.g., one project requires Python 2.x whereas the other is built upon Python 3.x.
Create a new Python environment named "workshop", and choose select 3.8 (the latest release). (Hint: The Location on the dialog tells you where this new environment is located at on your computer. )
Once the new environment is initialized successfully, a new environment appears under the base(root) in the middle panel. The right arrow indicts that the newly created environment is activated.
Cloning allows you to create a new environment (copy) from an existing environment.
Unlike the cloning that creates a copy from an existing environment on your computer, importing an environment enables you to create a new environment from an environment configuration file (.yml file)
Think of a scenario where you start a new collaboration with your colleagues on a Python project. Unlike your own Python settings (3.8), they use Python 2.x and the project requires very complicated package dependencies. In order to run their code with no errors, the best solution is to set up an environment exactly the same as theirs. You could simply ask your colleagues to export their environment to a YAML file and share it with you.
Exercises:
psychopy/conda/psychopy-env.yml
Save the YML file to your computer.
Mac Users: right-click the page-> Click Save Page As -> remove the extension.txt
& keep the format as Page Source
->Save
Windows Users: right-click the page-> Click Save as... -> remove the extension .txt
-> Save
Import
Not installed
from the dropdown menu. The default view shows a list of installed packages residing in this environment. Type Pandas
in the search window. You should see 9 packages matching "pandas". (Hint: if no packages return, click Update index...
next to the search window. This will update the package list of your computer)
Check the pakage pandas
and click Apply
button down below.
Install Packages
dialog prompts, showing 12 packages will be installed. Wait!? I just want to install one package. How come Anaconda installs 12 packages for me? --Package dependencies. Apply
to proceed. Installed
view and remove the words you typed in the search box to see the changes.Installed
view. Apply
button down below. Channels
button on the top. Add...
button.https://conda.anaconda.org/conda-forge/
into the white area and hit Enter. (Hint: conda-forge documentation)Update channels
button to proceed.
Question: How am I able to know the channel names? -- Explore the Anaconda Cloud. Anaconda Cloud is where data scientists share their work. You can search and download popular Python and R packages and notebooks to jumpstart your data science work.
Anaconda Prompt & PowerShell are two command-line interfaces (CLI) that come with the installation of Anaconda. To be exact, Anaconda did not install those two tools. Those two tools belong to the Windows OS. Anaconda just configured the environments of the CLI so that when you type a conda command, the shells know how to respond. CLI is also known as terminal or shell in Mac or Linux world, in which you communicate with OS through commands.
This section does not aim to teach you the Windows- or Mac- internal commands. Instead, you will learn conda commands to manager environments and packages. All the operations you have done in the Anaconda Navigator will be unified in here.
Mac users: Go to Anaconda-Navigator -> left-click the environment you work with (e.g., the base(root)) -> Choose Open Terminal
Windows Users: Go to Windows's Start menu -> Click either Anaconda Powershell Prompt(anaconda3) or Anaconda Prompt(anaconda3).
Resources 1. conda command reference 2. conda cheat sheet
conda create
or conda env create
conda create --name workshop2
conda create --name workshop2 python pandas
(Hint: you can append as many packages as possible)conda create --name workshop3 python=3.7 pandas
conda env create --name workshop5 --file xxx.yml
(Hint: this command works only when the xxx.yml is under the current working directory. If not, you need to pass in the full path to the yml file. )conda env remove
¶conda env remove --name workshop2
conda activate
, conda deactivate
conda activate workshop2
(Hint: this command deactivates the current working environment and activate the target environment)conda deactivate
(Hint: this command deactivates the current working environment and gets you back to the base/root environment.)conda env export >
conda env export > myenv.yml
(Hint: What if I want to export another environment? -- Activate that environment first)conda list
conda list
conda list --name workshop2
conda list pkgname
(Hint: Replace pkgname with a package name. This command list only the package info of that specified package. As you can tell, this command can also help if a package is installed or not.)conda install
conda install pkgname
(Hint: replace the pkgname with a package name)conda install pkgname=1.2
conda install --name workshp2 pkgname
conda install --channel chnname pkgname
(Hint: reaplce chnname with a channel name, e.g., conda-forge)conda remove
Note that when remving/uninstalling a package, all the packages that depend on that package will be removed as well.
conda remove pkgname
conda remove pkg1 pkg2 pkg3
conda remove --all
conda remove pkgname --force
conda update
conda udpate pkgname
conda update pkg1 pkg2 pkg3
conda update --all
conda update --name envname pkgname
conda search
conda search pkgname
conda search "pkg"
(Hint: this command searches for packages containing "pkg")Jupyter Notebook is an open-source browser-based application. It provides an interactive computing environment where users can put live code, narrative text, equations, images, videos and even widgets in one single place. This nature of interactivity redefines "programming" and makes learning Python engaging and fun.
Jupyter is a loose acronym for programming languages of Julia, Python and R that are the 3 languages Jupyter project supported in the first place. Today, however Jupyter Notebook can support over 40 programming languages. Here is a full list of supported languages.
Windows users: Open up Anaconda Powershell, and type the command: jupyter notebook
(Note: Do not close the terminal window, as it plays as a tunnel to communicate between the front-end Browser and the back-end Kernel.)
Mac Users: Open up Anaconda-Navigator -> Click the Environments
tab -> left-click the base environment -> choose Open with Jupyter Notebook
New
button on the top-right corner, and choose Python 3. Untitled
) The notebook is comprised of a sequence of cells. A cell is a multi-line text input area, and it can be executed. There are 3 types of cells:
When a cell is focused, there are two modes associated with it: command mode and edit mode.
Enter
key to get to the edit mode. Esc
key to get to the command mode. The possible actions include: Shift
+Enter
m
y
d
twice quickly More shortcuts can be found from the keyboard icon from the toolbar.