Setting Up Python and Django In Windows

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: 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.

Installer Screenshots

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.

Install Django

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 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!

Have Jenkins Run A Shell Script In A Remote Machine Every Time There Is A Change In The Git Repository

From Jenkins home page, click on “New Item” and select a “Freestyle Project” and fill in the general details such as “Project Name and Description”

Under the Source Code Management section, add your bitbucket url and set up the ssh credential so that Jenkins will be able to poll bitbucket after certain intervals.

To set up the ssh credential, generate a pair of public and private RSA key and put the public key in your bitbucket repo

and the private key in your Jenkins Source Code Management section by clicking on the “add” button which opens up a new window as shown below where you add in the ssh credential.

Then, we set up the Build Trigger section where we have Jenkins poll the repository we added in the earlier step. As shown in the figure, I am having it poll every 15 minutes.

Next thing we want to do is to step the Build Environment. In this step, we can set things that we want to do before and after the actual build step. I decided to run my test script before the build and the screenshot below shows the set up.

As you can see, you need to select the ssh server which is the remote machine where you want your script to run. To set up the ssh server, you need to go to the home page of Jenkins and select “Manage Jenkins” and select “Configure Jenkins” and set up your ssh server.

When you come back to this section after you set up your ssh server, you will see the name of your ssh server in the pull-down list. Here you can set up the ssh credential as password or key. I have set it as a password.

Since we are only running a shell script, there is nothing to build and that is the reason why my Build Section is empty.

The last step “Post-Build Section” is optional but you can use it to set up your email notification. But that’s it. Following the above steps will run your bash script every time there is a new code in your bitbucket repository. Since github is also a git repository the steps should be exactly the same I think.