Registrations Closing Soon for DevOps Certification Training by CloudxLab | Registrations Closing in

  Enroll Now

Create a virtual environment

What is a Virtual Environment?

  • As the name suggests, it is an environment virtually created to isolate the projects.

  • This isolation helps to avoid discrepancies between the different versions of the libraries or packages as used by different projects in our system.

Why do we use a Virtual Environment?

  • Let's say we want to use TensorFlow 2 in your project, which supports Python 3.5 - 3.8. However, you have Python 3.9 installed in your system. You can simply create a virtual environment with a compatible version of Python and install TenforFlow 2 inside that virtual environment. So, all your other projects which requires Python 3.9 can continue to use the same.

How to create a Virtual Environment?

  • Creating a Virtual Environment: We create a python3 virtual environment with the name we mention using the following command:

    virtualenv -p python3 <<your virtual environment name>>
    

    Ex: virtualenv -p python3 my_first_venv creates a virtual environment named my_first_venv.

  • Activating a Virtual Environment: After creating the virtual environment, we switch to that environment to create our project and install the dependencies inside that environment. We switch to a virtual environment using the following command:

    source <<your virtual environment name>>/bin/activate
    

    Ex: source my_first_venv/bin/activate command switches to the virtual environment named my_first_venv.

  • Deactivating a Virtual Environment: To exit the environment, we just need to use the command:

    deactivate
    
INSTRUCTIONS
  • First, switch to Python 3

    export PATH=/usr/local/anaconda/bin:$PATH
    
  • Now, create a virtual environment named Dead-Code-Sample

    virtualenv -p python3 Dead-Code-Sample
    
  • Activate the virtual environment you created

    source Dead-Code-Sample/bin/activate
    

No hints are availble for this assesment

Answer is not availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...