While setting Python and Django in Linux and MAC is fairly straight-forward, it could be a little challenging to set up Python in Windows machine. In this tutorial, I will guide you through the steps:
Install Anaconda Distribution of Python
Anaconda Distribution of python comes with several packages and package manager such as conda that makes speeds up up the initial set up process for python. At the time of this writing, Anaconda Python is the world’s most popular distribution of Python.
Download it from here: https://www.anaconda.com/download/#windows and choose your version of Python to download.
After you hit the download button, it may ask to enter your email in which case you may choose to skip and download the installer.
After the download is complete, double click on the downloaded installer and it will start a wizard which will install the Anaconda Python.Basically, you can continue hitting next leaving all the default settings as is. I have taken a few screenshots of the wizard.
After successful installation, you can see from the start menu the programs that was installed. As you can see from the figure below, the following programs were installed:
- Anaconda Navigator
- Anaconda Prompt
- Jupyter Notebook
- Spyder IDE (Integrated Development Environment)
You can learn more about them as you make progress with your Python learning, but in this tutorial we will be using Anaconda Prompt.
Django is a popular web development framework for Python. Anaconda Python includes Django in its distribution which can be installed using its package manager called “conda”. Open the Anaconda Prompt program from the windows start menu and run the command “conda install django” to install Django.
Type y at the prompt and it should install django which you can check by running the command “python -m django –version”
Creating a django project
To create a django project, run the command “django-admin startpproject mysite”
As you can see from above figure, that a folder named “mysite” was created in the Documents folder. Note: “ls” equivalent in windows is “dir”
Running the server
Go to the mysite directory and run “python manage.py runserver” which will start the server.
Using PyCharm IDE
Although Spyder IDE was installed with Anaconda Python, PyCharm is the most popular IDE for Python and I will show you how to set up your PyCharm to use Anaconda Python. Download and Install the community version of PyCharm. After successful installation, open PyCharm from the windows start menu. At the start, it will ask you whether to create a new project or open an existing project. When you open a new project, you can select the django’s mysite project that we just created earlier from the Anaconda Prompt.
If you already were using some other Python in your PyCharm, you can change your project to use Anaconda Python from now on by going to the settings under File and changing the Python Interpreter to Anaconda Python. See the screenshot below:
Whenever you create a new project in PyCharm, you can tell it use Anaconda Python by selecting the right interpreter as shown in the picture below:
Hope that helps. Happy coding!