How to Create Virtual Environment in Django
May 17, 2021 2022-12-19 7:26How to Create Virtual Environment in Django
How to Create Virtual Environment in Django
How to create virtual environment in Django
You know we write Django tutorials for our readers. We try to share knowledge in a simple and easy way as possible. So in this Django tutorial, we will share knowledge related to “how to create virtual environment in Django”. So read up to the end if you want to get a real understanding. let’s learn more!
Developer work on a different project at the same time at the same machine. And every project has different dependencies, for this reason, we need to create such an environment in which every project should be separated from another one. To complete this idea, a virtual environment concept is developed it means you can create an environment in which you will get an isolated python installed environment.
When you create a virtual environment you will get all the files/folders when you install python globally e.g pip etc. So, in that environment you will be allowed to create a project that will be separated from another project, you can set its own version to mix up with other versions of another environment.
Why need of Virtual Environment
Actually, there are some reasons you have to build your project in a virtual environment that points I want to share with you.
1. If you want to work on another project on the same machine, then you have to think about VE.
2. You also need when you want to work on different versions of Python
3. Other reasons, if your python project version is 2.0 without virtual environment and you have launched that project also on the hand of users. When other releases come e.g 3.0 then it may be some issue with your previous project because there may be some functions, module stop working because the new update is released. And you know when a new update has released some functions or models are changed to another one. Then your project will be affected by releasing a new update. So, you have to build your project in a virtual environment to avoid such kinds of difficulties.
We have written a complete guide on the need for a virtual environment you can read that tutorial from starting to end.
Why does Django need a virtual environment?
How to create virtual environment
Creating a virtual environment is a different way on the different operating systems. I will teach how to create a virtual environment on Windows as well as on Linux. So following the command will helpful for you.
Python virtual environment Windows, Linux, and macOS
- First of all, you have to open the terminal (cmd) in that folder location in which you want to save the Django project. Then run the following command to install the virtual environment first
     on windowÂ
     pip install virtualenv
     on Linux and macOS
     python3 -m pip install –user virtualenv
2. After installation, then create virtual environment , you have to write virtualenv “here your name of virtual            environment without quotes”
     on windowÂ
     virtualenv test
      on Linux and macOS
      python3 -m venv env
3. Next is to activate the virtual environment you created now. Run the following command to activate the virtual environment.
      on windowÂ
      \test\Scripts\activate
      on Linux and macOS
      source env/bin/activate
Conclusion
We have discussed how to create virtual environment in Windows as well as Linux and macOS. Anyhow, if you have any problems or issues related to creating virtual environment then share with us we will help you as possible.
If you use Facebook, Twitter, Pinterest, LinkedIn, or other social media platforms, then share this Django tutorial, if you share, more students will take the chance to learn.
Thank you in advance!