HOW TO SET UP A VIRTUAL ENVIRONMENT USING ANACONDA/CONDA
Published: 2024-05-27 08:23:33

**HOW TO SETUP VIRTUAL ENVIRONMENT USING CONDA /ANACONDA**

**TABLE OF CONTENT** 
    - Introduction to Anaconda and Virtual Environments
    - Installing Anaconda
    - Creating a Virtual Environment
    - Activating the Virtual Environment
    - Deactivating and Deleting the Environment
    - Installing Additional Packages
**Introduction to Anaconda and Virtual Environments**

Anaconda is a distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment. The distribution includes data-science packages suitable for Windows, Linux, and macOS.
A virtual environment is a networked application that allows a user to interact with both the computing environment and the work of other users.

**Installing Anaconda**

1. Download Anaconda
2. Visit the Anaconda website and download the Anaconda distribution that matches your operating system (Windows, macOS, or Linux). Choose between Anaconda Individual Edition or Anaconda Team Edition based on your needs.


![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716382445879_Screenshot+45.png)



**2. Run the Installer**
Once the download is complete, run the installer by double-clicking on the downloaded file.

![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716383034986_Screenshot+47.png)


**3. Follow the Installation Wizard**
The installation wizard will guide you through the installation process.27 u

![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716383087969_Screenshot+46.png)


**4.Complete the Installation**
   Once you've completed theuu installation settings, proceed with the installation process. It may take a few minutes for Anaconda to install all the necessary components.

**5.Verify the Installation**
After the installation is complete, you can verify that Anaconda was installed correctly by opening a terminal or command prompt and running the following command:
 

![](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716437089272_Screenshot+from+2024-05-22+15-29-14.png)



    conda --version

This command should display the version of Conda that was installed with Anaconda.
6. Update Anaconda (Optional)
It's a good idea to update Anaconda after installation to ensure you have the latest packages and bug fixes. You can update Anaconda by running:

    conda update --all

**7. Start Using Anaconda**
Once Anaconda is installed, you can start using it to create environments, install packages, and manage your Python projects effectively.

    pip install vlc //for our case we created vlc music player

**1.Creating a Virtual Environment**

    bash Anaconda3-2024.3.sh // activate it by 
    

**2. Run the Installer**
Once the download is complete, run the installer by double-clicking on the downloaded file. or 

![](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716403850786_Screenshot+from+2024-05-22+15-27-14.png)
![](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716403826529_Screenshot+from+2024-05-22+15-31-25.png)

**3. Follow the Installation Wizard**
The installation wizard will guide you through the installation process. You will be prompted to review and accept the license agreement, choose the installation location (default is recommended), and select whether to add Anaconda to your system PATH environment variable (recommended). It should display this on Linux.


    
![](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716437391157_Screenshot+from+2024-05-22+15-28-59.png)


** 4. Complete the installation**  
 Once you've completed the installation settings, proceed with the installation process. It may take a few minutes for Anaconda to install all the necessary components. 

**5. Verify the Installation**

 After the installation is complete, you can verify that Anaconda was installed correctly by opening a terminal prompt and running the following command:

    conda --version
    anaconda --version

This command should display the version of Conda that was installed with Anaconda. 
**
6. Update Anaconda (Optional)**

It's a good idea to update Anaconda after installation to ensure you have the latest packages and bug fixes. You can update Anaconda by running:


    conda update --all
**7. Start Using Anaconda**

Once Anaconda is installed, you can start using it to create environments, install packages, and manage your Python projects effectively.
That's it! You have successfully installed Anaconda on your system. Now you can start using it to manage your Python environmentsand packages.
Creating a Virtual Environment
Now your command prompt will display the active environment’s generic name, which is the name of the environment's root folder:

    $ cd anaconda
    $ conda activate GroupH
    (groupH) dennis@dennis-HP-Laptop-15-bs0xx:~$ cd anaconda
Updating an environment

Run the following commands

    - conda list
    -conda --version
    -conda update conda
    -conda update anaconda
    - conda update anaconda-navigator

Now Lets Create  A virtual Environment 
Use the terminal for the following steps:

**1. To create an environment:**
    conda create --name GroupH
    
**2. When conda asks you to proceed, type `y`:**
    proceed ([y]/n)?

This creates the my env environment in `/envs/`. No packages will be installed in this environment.
**3.To create an environment with a specific version of Python:**

    conda create -n GroupH python=3.9

**4.To create an environment with a specific package:**

    conda create -n GroupH scipy

or:

    conda create -n GroupH python
    conda install -n GroupH scipy

**5.To create an environment with a specific version of Python and multiple packages:**

    conda create -n GroupH python=3.9 scipy=0.17.3 astroid babel
    




Specifying a location for an environment

:You can control where a conda environment lives by providing a path to a target directory when creating the environment. For example, the following command will create a new environment in a subdirectory of the current working directory called `envs`:

    conda create --prefix ./envs jupyterlab=3.2 matplotlib=3.5 numpy=1.21

**You then activate an environment created with a prefix using the same command used to activate environments created by name:**

    conda activate ./envs

Specifying a path to a subdirectory of your project directory when creating an environment has the following benefits:

- It makes it easy to tell if your project uses an isolated environment by including the environment as a subdirectory.
- It makes your project more self-contained as everything, including the required software, is contained in a single project directory. Activate Environment.

**To activate a Conda virtual environment, use the following command:**

    conda activate groupH

This will switch your current terminal session to use the specified Conda environment. 

**Deactivating Environment.**
To deactivate a Conda virtual environment, use the following command:

    conda deactivate

This command will switch your terminal session back to the base environment, effectively deactivating the current virtual environment. You can then switch to another environment or continue using the base environment for your work.

**Building identical conda environments**

You can use explicit specification files to build an identical conda environment on the same operating system platform, either on the same machine or on a different machine.
Use the terminal for the following steps:

1. Run `conda list --explicit` to produce a spec list such as:
    @EXPLICIT
    https://repo.anaconda.com/pkgs/free/osx-64/numpy-1.11.1-py35_0.tar.bz2
    
![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716555970943_Screenshot+50.png)

    https://repo.anaconda.com/pkgs/free/osx-64/pip-8.1.2-py35_0.tar.bz2
    
![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716555980972_Screenshot+51.png)

    https://repo.anaconda.com/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
    
![](https://paper-attachments.dropboxusercontent.com/s_44C0AF156A871C1E8A1D9B1FD6FB9D782B32B6CA6AECDAA50CC7FF6996BD1ACE_1716556139228_Screenshot+52.png)

    https://repo.anaconda.com/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
    
![](/static/img/pixel.gif)

1. To create this spec list as a file in the current working directory, run:
    conda list --explicit > spec-file.txt
1. Note
2. You can use `spec-file.txt` as the filename or replace it with a filename of your choice.
3. An explicit spec file is not usually cross platform, and therefore has a comment at the top such as `# platform: osx-64` showing the platform where it was created. This platform is the one where this spec file is known to work. On other platforms, the packages specified might not be available or dependencies might be missing for some of the key packages already in the spec.
4. To use the spec file to create an identical environment on the same machine or another machine:
    conda create --name myenv --file spec-file.txt
1. To use the spec file to install its listed packages into an existing environment:
    conda install --name myenv --file spec-file.txt
1. Conda does not check architecture or dependencies when installing from a spec file. To ensure that the packages work correctly, make sure that the file was created from a working environment, and use it on the same architecture, operating system, and platform, such as linux-64 or osx-64.

Creating a virtual environment with Anaconda is a breeze.
Here's how you can do it:

**1. Open Anaconda Prompt or Terminal**
- Windows: You can find Anaconda Prompt in the Start menu.
- macOS/Linux: Open a Terminal.
1. Create a New Virtual Environment
2. To create a new virtual environment, you can use the `conda create` command. For example, to create an environment named groupH:


    conda create --name groupH

You can also specify a particular Python version for your environment:


    conda create --name groupH python=3.9

**3. Activate the Virtual Environment:**
Once the environment is created, you need to activate it. On Windows, use:


    conda activate groupH

On macOS/Linux:

    source activate groupH

**4. Deactivate the Virtual Environment**
To deactivate the environment, simply use:

    conda deactivate

or

    source deactivate

**5. List Environments**
To see a list of all your created environments, use:


    conda env list

**6. Remove an Environment**
If you want to remove an environment, you can do so with:


    conda remove --name groupH --all


After successful installation of packages -your dashboard should look like this :

![](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716440060550_dash.png)


Nagivate to Enviroments and Click GroupH  

![Launch Visual studio or any other text Editor](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716440664113_conta+GroupH+LIST.png)


**Install VLC and Python Libraries**

1. Install Python Librarie27 perjo .
    - You might need libraries like `python-vlc` for interfacing with VLC from Python.
    - Install the required libraries in your environment:
    conda install vlc 


![simple code vlc music player](https://paper-attachments.dropboxusercontent.com/s_B463B3373C5E799C73D48FBD4A40C0B4CAE0C3A08791104C0683EF8265AD4B75_1716441024244_image.png)


Storage is Local Drive (for this case study )
**
References **

1. https://www.anaconda.com/download/success
2. https://docs.anaconda.com/index.html
3. https://www.anaconda.com/download
4. https://www.digitalocean.com/community/tutorials/how-to-install-the-anaconda-python-distribution-on-ubuntu-20-04