Be sure to like, share and comment to show your support for our tutorials.
Channel - https://goo.gl/pnKLqE
Playlist For This Tutorial - https://goo.gl/EyZFti
Latest Video - https://goo.gl/atWRkF
Facebook - https://www.facebook.com/mastercodeonline/
Twitter - https://twitter.com/mastercodeonlin?lang=en
Website - http://mastercode.online
In this Django Tutorial, we will install virtualenv to allow us to have a virtual environment for our Django project.
Setup A Virtual Environment For Django
When working with Django or any Python project it is highly recommended that you use something called a virtual environment. In this Django tutorial, we will install and setup a virtual environment for Django on your computer. If you have already setup a virtual environment on your computer and are comfortable using the virtual environment you can move on to the next Django tutorial.
What is a Virtual Environment?
Virtual environment can mean many things but in our case, virtual environment means that we will install our required software in a separate directory and when the virtual environment is activated our directory is completely separated from the rest of our other directories on our system.
Why Use A Virtual Environment?
When working with many of projects in Django or Python you may require different versions of specific packages. For example, you may build one website using Django 1.9 and then build another utilizing 1.10 in this case, you would need two different versions of Django on your machine. Running two separate versions of Django on your machine without a virtual environment would be difficult and not very smart. A virtual environment provides version control and extra security to each project. What I mean by security, is that you do not change or delete required packages for your project.
Virtual environments also help keep your system clean by packaging each project together in a separate directory.
How To Setup A Virtual Environment On Your System
Python has an excellent package that will allow us to create a virtual environment for our system. This package is called virtualenv. virtualenv is a powerful package used by most Python programmers if you would like to learn more about virtualenv I suggest you visit the official documentation at https://virtualenv.pypa.io/en/stable/
How To Install virtualenv
*Note – Do you have two versions of Python installed on your system? It is important to ensure you work with Python3 for this tutorial series. If you have two versions installed please be aware which is Python 3. For example, I have two versions on my computer. I have Python 2 and Python 3. I can access Python 2 using just the python command and for Python 3 I would use python3. Now with that being said if I wish to install a package for Python 3 I call the Python package installer like this “pip3”. If you only have one version you may just need to call the Python package installer like this “pip”. Not sure which one use this command “python –version” if it returns Python 3.5.x then use “pip” if it returns Python 2.7.X then try “python3 –version” if that returns Python 3.5.x then use “pip3”. If you do not get Python 3.5.x on either version check then you properly did not install Python 3.
Not sure which one use this command “python –version” if it returns Python 3.5.x then use “pip” if it returns Python 2.7.X then try “python3 –version” if that returns Python 3.5.x then use “pip3”. If you do not get Python 3.5.x on either version check then you properly did not install Python 3.
To install virtualenv it is very simple. Just follow the steps below.
Step 1: Open your terminal or command prompt
Step 2: Enter the following command