Setup Django Mac: How To Install Django On Mac
In this tutorial, I will show you How To Install Django On Mac. Django is available open-source under the BSD license. We recommend using the latest version of Python 3. If you plan to use Django’s database API functionality, you’ll need to ensure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MariaDB, MySQL, Oracle, and SQLite.
What is Django Framework
Django is the web framework developed in Python. Django is the high-level Python Web framework that encourages rapid development and clean, pragmatic design. It takes care of much of a hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. In addition, it is free and open-source.
Virtual Environments keep project dependencies mostly isolated from one another. Therefore, I recommend that for each project you create, you use a different virtual environment. Below, we use the virtual environment manager Pipenv.
PIP, or Python Package Installer, allows you to install all types of Python-related software (and code) include Django, virtual environments (virtualenv, pipenv, etc.), Flask, Tensorflow, Python Requests, and more.
Some of the advantages of the Django framework are as follows.
Advantages of Django Framework
- Ridiculously fast.
- Reassuringly secure.
- Exceedingly scalable.
- Incredibly versatile.
- Fully loaded.
How To Install Django on Mac
To install Django on mac, we have to follow the below steps.
- If you have not installed Python 3, then please install Python 3.
- Install pip or upgrade pip.
- Install virtual environment package virtualenv to isolate the Django project.
- Install the Django framework using pip.
We often come across various tutorials for separate technologies but not a precise, compact form of it. In this article, I aggregate the basic setup needed to start a Python-Django project on macOS X.
Here we will be creating a virtual environment on your system which will contain your project with python3.6 and django2.0. Well, we will install it from scratch. First, I will show you how to install Python on Mac, then how to install virtualenv, and then we install Django on that virtual environment.
Step 1: Install Python on Mac.
Python is already installed on a brand new Mac, but its version is old. So what we do is to install the latest version of python using homebrew.
brew install python3
Okay, after it will complete the installation, you will type the following command to check the version. First, type python3 in your terminal. Since MacOS X already has python installed, we cannot uninstall the old version because otherwise, the Python 2 supported programs will be stopped, and we need to reinstall the mac. So we need to type python3 instead of python.
It will display the version, and now we can execute the python code. I am using iTerm2, so your terminal may be different, but it does not matter with any commands anyway.
Okay, so we have successfully installed python 3. Now, to out from the python console, we need to type exit().
Step 2: Install Pip package management system.
Pip is the package management system used to install and manage software packages written in Python. Now, install it using the following command.
sudo easy_install pip
Step 3: Install virtualenv for python.
Now, type this command in your terminal.
sudo pip install virtualenv
Okay, after installing, we need to create a virtual environment. Now you will create this folder when you are putting your other projects. Mine is desktop >> code folder. So navigate to that and type the following command. In my case, My virtualenv folder name is thanos.
Okay, so it will install the required folders. Now, go into that folder.
Now, activate the virtual environment by typing the following command. First, please Make sure you are in the virtual environment directory.
You will see what your terminal looks like below.
So, our virtual environment has been started. Now, this is the time to install the Django Framework.
Step 4: Install Django On Mac
Okay, now stay in that folder and install Django using the following command.
sudo pip install django==3.0.1
It will download the Django project. Check the Django version using the following command.
python -m django --version
In our case, we have explicitly defined that we are installing 3.0.1. So it will display that version.
Step 5: Create the Django Project.
We need to install the skeleton of the Django project.
So type the following command.
django-admin startproject thanosback
Here, our project name is thanosback. So, next, go into that folder.
Finally, we have created the project. Now start the project server by typing the following command.
python manage.py runserver
It has started the development server, and we can access it via localhost:8000
Navigate to the browser, and you will see a screen like this.
Step 6: Open Django on Visual Studio Code.
If you have not installed Visual Studio Code on Mac, then please check out my below tutorial.
Related Post: How To Install Visual Studio Code On Mac
This step is optional because if you are using Visual Studio Code, then it will be helpful to you.
If you are using another IDE like pycharm or editor like sublime text, then you can skip this step. But, first, perform the following step.
Install the Python extension.
Now, open our project in the visual studio code using the following command.
Please make sure you are at the root of the thanosback folder.
You will get the folder structure like this.
Get the latest development Django version.
The latest and greatest Django version is the one that’s in our Git repository (our revision-control system).
This is only for experienced users who want to try incoming changes and help identify bugs before an official release. Get it using this shell command, which requires Git:
Type the following command to get the development version.
git clone https://github.com/django/django.git
That’s it for this tutorial.