How to Create and Activate Virtual Environment In Linux ?

 

How to Create and Activate Virtual Environment In Linux ?


A short tutorial on creating and activating virtual environment in Linux .

Image Credit - Source


In this short tutorial , I will be using Ubuntu Linux distro to explain the whole process of creating and activating virtual environment in Linux .

Creating virtual environment


Follow the steps below to create a virtual environment in your system .

  • Open terminal in your Linux distro .You can directly press Ctrl + Alt +T to open terminal , or search ‘ terminal ’ after pressing super key and hit enter .

Source - Author

  • Create a directory you wish to use as a virtual environment . Here , I am giving directory name as ‘ virenv ’ . Your are free to give any name to the directory as per your choice . To create the directory , type ‘ mkdir directory_name ’ in the terminal as shown in the screenshot below .

  • Source - Author
    • Now , cd into the directory you just created by typing ‘ cd directory_name ’ as shown in the screenshot below .
    • Source - Author

  • Type the below command in the terminal to create the virtual environment . Please ensure that you have Python 3 and virtualenv are installed in your system . 
  • $ virtualenv -p python3 .

  • Please note that there is a dot at the end of the above command which indicates that we are creating a virtual environment in the current directory . After the command is executed , you are done . Your virtual environment is created .
  • Source - Author

    Get into your virtual environment by typing the command below in the same directory in which you have just created it . 


    $ source bin/activate

  • Source - Author

    And you are in .

    Now , you can see the current directory name before the $ sign . This indicates that your virtual environment has been created . Here , you can keep you files and install specific version of libraries suited for your project .

    Note — The specific version of library installed within the virtual environment will not be available outside it .

    To remove virtual environment , simply delete the directory in which it is created . You can do this in the terminal by typing ‘ rm -rf directory name ’ . ( Type the below command in terminal of your system .)

    $ rm -rf virenv

    Source - Author

    Thanks for reading !


    Feel free to comment below if you got stuck anywhere in the steps . I will be glad to help you out .






Comments

Popular posts from this blog

How to get Winter and Summer Internship at IIT Bhubneshwar ?