DEV Community

Cover image for HOW TO SET UP A VIRTUAL ENVIRONMENT USING ANACONDA/CONDA
Faith Karuga
Faith Karuga

Posted on

HOW TO SET UP A VIRTUAL ENVIRONMENT USING ANACONDA/CONDA

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.

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

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

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:

conda --version
Enter fullscreen mode Exit fullscreen mode

This command should display the version of Conda that was installed with Anaconda.

  1. 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
Enter fullscreen mode Exit fullscreen mode

1.Creating a Virtual Environment

bash Anaconda3-2024.3.sh // activate it by 
Enter fullscreen mode Exit fullscreen mode

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


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.

** 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
Enter fullscreen mode Exit fullscreen mode

This command should display the version of Conda that was installed with Anaconda.
**

  1. 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Updating an environment

Run the following commands

- conda list
-conda --version
-conda update conda
-conda update anaconda
- conda update anaconda-navigator
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

4.To create an environment with a specific package:

conda create -n GroupH scipy
Enter fullscreen mode Exit fullscreen mode

or:

conda create -n GroupH python
conda install -n GroupH scipy
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

conda activate ./envs
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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://repo.anaconda.com/pkgs/free/osx-64/pip-8.1.2-py35_0.tar.bz2
Enter fullscreen mode Exit fullscreen mode

https://repo.anaconda.com/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
Enter fullscreen mode Exit fullscreen mode

https://repo.anaconda.com/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
Enter fullscreen mode Exit fullscreen mode

  1. To create this spec list as a file in the current working directory, run: conda list --explicit > spec-file.txt
  2. Note
  3. You can use spec-file.txt as the filename or replace it with a filename of your choice.
  4. 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.
  5. 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
  6. To use the spec file to install its listed packages into an existing environment: conda install --name myenv --file spec-file.txt
  7. 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.
  • Create a New Virtual Environment
  • 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
Enter fullscreen mode Exit fullscreen mode

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

conda activate groupH
Enter fullscreen mode Exit fullscreen mode

On macOS/Linux:

source activate groupH
Enter fullscreen mode Exit fullscreen mode

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

conda deactivate
Enter fullscreen mode Exit fullscreen mode

or

source deactivate
Enter fullscreen mode Exit fullscreen mode

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

conda env list
Enter fullscreen mode Exit fullscreen mode

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

conda remove --name groupH --all
Enter fullscreen mode Exit fullscreen mode

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

Nagivate to Enviroments and Click GroupH

Launch Visual studio or any other text Editor

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

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

Top comments (0)