Setting Up Environment

Anaconda, jupyter-lab and jupyter-notebooks and vscode

Mfundo Monchwe

Welcome to setting up environment in Anaconda and Vscode

This presentation will cover the the following:

  1. Introduction to Environments - Explanation of why environments are important for managing dependencies.
-   Benefits of isolating projects environments
  1. Installing Anaconda - Download anaconda for your OS (windows or Linux, Mac)
-   Understand the Anaconda Navigator and prompts
  1. Creating Conda Environmens - Introduction to conda package manager
-    Creating a new environment using `conda create`

-   Specifying Python version and dependencies
  1. Working With Jupyter Notebooks - Launching Jupyter Noteebok from Anaconda from the Anaconda Navigator
-   Opening, Creating, and saving notebooks

-   Executing code cells and adding markdown content
  1. Setting Up JupyterLab - Installing Jupyter in your environment
-   Launching from Anaconda prompt

-   Overview of JupyteLab Interface
  1. Jupyter vs. JupyterLab - Compare the features and benefits of Jupyter Notebook and JupyterLab
-   Choosing the interface that suits your needs
  1. Using Conda Environments in Jupyter - Activate your environment within Jupyter
-    Ensuring that your notebook uses the correct environment's Python
  1. Using Visual Studio Code (VSCode) - Introduction to VsCode as a powerful editor
-   Installing the python extension in Vscode
  1. Configuring VSCode for Conda Environments - Setting up Vscode to work with conda environments.
-   Selecting the desired environment for your project
  1. Extensions for Vscode - Additional Bonus

1. Introduction to Environments

  • click here to download anaconda

    print("Hello World")

Why Environments Matter?

When working on software projects, especially in Python, managing dependencies and ensuring a consistent environment is crucial. Environments play a key role in achieving this goal.

Benefits of Using Environments

  1. Isolation of Dependencies: Environments allow you to isolate the packages and libraries used in different projects. This isolation prevents conflicts between packages that might have incompatible versions, ensuring that your projects run smoothly.

  2. Version Control: Environments make it easier to track the specific versions of packages used in your project. This is essential for maintaining reproducibility and sharing your work with others.

  3. Easy Collaboration: Environments enable collaboration by providing a clear way to share the exact environment configuration with others. This means that anyone can recreate your project’s environment and run your code without worrying about compatibility issues.

  4. Experimentation: Environments give you the freedom to experiment with new libraries, packages, and configurations without affecting your system-wide Python installation. This helps you test different setups without risking your overall development environment.

  5. Development and Production Parity: Environments help ensure that the environment you develop in matches the production environment. This reduces the chances of unexpected issues arising when you deploy your code.

  6. Clean and Organized Development: By creating separate environments for different projects, you keep your development environment clean and organized. This makes it easier to manage your projects and avoid clutter.

  7. Streamlined Dependency Management: Environments, especially those managed by tools like conda or pip, simplify the process of installing, updating, and removing packages. This reduces the likelihood of package conflicts.

  8. Interdisciplinary Work: Environments enable collaboration between developers from different disciplines, each with their own set of tools and libraries. Each developer can work in their own environment tailored to their needs.

2. Installing Anaconda

After you have installed the anaconda

  • click to install, select jupyter notebook to launch it alternative you can try the following command
jupyter notebook
jupyter-lab

3. Creating Conda Environments

Benefits of Conda Environments

  1. Dependency Isolation: Preventing conflicts between package versions.
  2. Reproducibility: Ensuring consistent environments for development and sharing.
  3. Easy Setup: Quickly switching between different project requirements.
  4. Custom Configurations: Installing specific packages and versions for each project.

Creating a New Conda Environment

  1. Using Conda Command:

    conda create --name my env
  2. Specify Python Version:

    conda create --name my env python=3.9
  1. Adding Packages at Creation:

    conda create --name flask-project flask

    Activating and Deactivating Environments

    1. Activate an Environment:

    • Windows:
     conda activate flask-project
    • macOS/Linux:
    source activate flask-project

    2. Deactivate an Environment

    • Windows:
    conda deactivate
    • macOS/Linux:
    source deactivate

    Listing and Managing Environments

    - Using `conda env list` to list existing environments

    - Using `conda remove —name flask-project —all` to remove an environment.

  1. Creating virtual envs in Jupyterlab

    • first create new env

      conda create -n flask_env
    • activate your env

      conda activate flask_env
    • install a the library

      pip install Flask
    • install the kernel

      conda install ipykernel
    • install the kernel to your env

      python -m ipykernel install --userl --name=flask_env
  2. remove kernel

    1. run the kernel list jupytrer kernelspec list

    2. Find the name of the kernel you want to remove in the list

    3. run the following command:

      jupyter kernelspec uninstall <kernel_name>
  3. Creating new env using pswh (Powershell)

    - press ctrl + shift +` and write the following cmd:

      python -m venv flask_project

    - Activate the environment

     ./flash_project/Scripts/Activate.ps1

    - Install flask library using pip

       pip install flask

    - After installation:

       flask run

6. Jupyter vs JupyterLab

Introduction

In this section, we’ll compare Jupyter Notebook and JupyterLab, two popular environments for interactive coding and data analysis.

Jupyter Notebook

  • Explanation of Jupyter Notebook as a web application for creating and sharing documents that contain live code, equations, visualizations, and narrative text.

  • Showcase of Jupyter Notebook’s user interface and features.

JupyterLab

  • Introduction to JupyterLab, an interactive development environment.

  • Highlighting JupyterLab’s enhanced capabilities, including a flexible UI and improved multi-document workflows.

Feature Comparison

  • Interface: Comparing the interfaces of Jupyter Notebook and JupyterLab.

  • Extension Ecosystem: Exploring the diverse extension ecosystem of JupyterLab.

  • User Experience: Discussing user experience enhancements in JupyterLab.

Choosing the Right Tool

  • Factors to consider when choosing between Jupyter Notebook and JupyterLab.

  • Use cases and scenarios where each tool shines.

7. Using Conda Environments in Jupyter

Introduction

In this section, we’ll learn how to utilize Conda environments effectively within Jupyter environments.

Launching Jupyter Notebook

  • Activating a Conda environment in your terminal.

  • Running jupyter notebook to launch the Jupyter Notebook interface.

Selecting the Right Kernel

  • Exploring how Conda environments are integrated as kernels in Jupyter.

  • Choosing the correct kernel to match your project’s environment.

Installing Additional Kernels

  • Demonstrating how to install and manage additional kernels using Conda.

  • Using different Python versions in your notebooks.

Running JupyterLab in an Environment

  • Activating your Conda environment.

  • Running jupyter lab to launch JupyterLab.

Using Conda Environments in JupyterLab

  • Understanding JupyterLab’s environment-awareness.

  • Switching between Conda environments for different notebooks.

8. Using Visual Studio Code (VSCode)

Introduction

In this section, we’ll explore how to set up and use Visual Studio Code (VSCode) as a powerful integrated development environment (IDE) for Python projects.

Why Use VSCode for Python?

  • Explanation of VSCode’s features: code editing, debugging, version control, extensions, and more.

  • How VSCode can enhance your Python development workflow.

Installing the Python Extension

  • How to install the Python extension in VSCode.

  • Demonstration of the extension’s capabilities.

Creating a New Project

  • Overview of creating a new project folder in VSCode.

  • Using VSCode’s integrated terminal for commands.

9. Configuring VSCode for Conda Environments

Introduction

In this section, we’ll learn how to configure VSCode to work seamlessly with Conda environments.

Setting Up the Python Interpreter

  • How to select and configure the Python interpreter in VSCode.

  • Choosing the interpreter from your Conda environment.

Installing Additional Extensions

  • Exploring VSCode extensions that enhance Python development.

  • Installing and configuring extensions for linting, formatting, and more.

Managing Conda Environments in VSCode

  • Overview of managing Conda environments from within VSCode.

  • Using the integrated terminal for activating environments.

Running and Debugging Python Code

  • Running Python scripts within VSCode.

  • Setting breakpoints and debugging code with VSCode’s debugger.