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
- Download Anaconda
- 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
This command should display the version of Conda that was installed with Anaconda.
-
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
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
This command should display the version of Conda that was installed with Anaconda.
**
- 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:
- 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
https://repo.anaconda.com/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
- To create this spec list as a file in the current working directory, run: conda list --explicit > spec-file.txt
- Note
- You can use
spec-file.txt
as the filename or replace it with a filename of your choice. - 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. - 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
- To use the spec file to install its listed packages into an existing environment: conda install --name myenv --file spec-file.txt
- 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
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 :
Nagivate to Enviroments and Click GroupH
Install VLC and Python Libraries
- 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
- You might need libraries like
Storage is Local Drive (for this case study )
**
References **
Top comments (0)