Setup Python Development Environment – Windows

by | 2 Oct 2017 | Coding Journey | 0 comments

Lets Prepare Your Computer for Some Coding

 

Downloading Python 3

Let’s start from installing Python 3 on your operating system – you can download it here. I recommend Python 3 as this is what is currently being developed all the time and version 2.7 is no longer modernised as there were issues that could not be solved without rewriting too much. In the end it’s like with a steam engine and jet propulsion. Sure you can use both but which one wins the race eventually?

Installing Python 3 on Windows

  • Download and execute the newest Python 3 installer. 
  • Choose the path to install.
  • Make sure you tick the boxes: “Add Python to environment variables” and “Associate files with Python”. This will make your scripts executable from command line.

Choice of Your IDE (Integrated Development Environment)

Now that we have the installation of the programming language done we can carry on and install a proper Integrated Development Environment (IDE). Although Python always comes with its basic IDE called IDLE (and if you want you can write scripts even in the most basic text editor like Notepad) I strongly suggest that you get used to a software used by professionals as it will make things a lot easier later on.

For me my IDE of choice for Python is PyCharm from JetBrains (note that the free of charge community version does not have some advanced features but you do not need them to start with).

Some of PyCharm’s benefits:

  • It is cross platform – so if you learn it once, you can use it pretty much the same way on Win / Linux / Mac (but so are other editors too).
  • It has syntax highlighting for plenty of languages.
  • It is continously being upgraded. 
  • It contains pretty much all the necessary tools for your programming needs in one neat package and I mean it has looooads of stuff in it.
  • There are numerous plugins and improvements from JetBrains or other sources.
  • And so on and so on.

Other Choices of IDEs

Some names to throw at you: Vim (keyboard only :)), Sublime, or Atom.

Whichever editor you choose please print a cheatsheet with all keyboard shortcuts for it (or at least the most important ones) and force yourself to use them instead of navigating everything with a mouse. It will be a pain in the backside at first but within a week you will thank me for forcing you to do that. The way I do it is I look at the menu element I want to select or a function to perform and I check what is it’s shortcut in my cheatsheet. I use the shortcut. Eventually you do not have to look at the cheatsheet anymore (same principle works perfectly if you want to master any computer game). It works. Try it. You will like it.

The default keymap for PyCharm is here.

Using Virtual Environments (And Wrappers for Them)

Pretty quickly you will find that your main Python installation gets clogged up with additional packages and libraries that you install. To prevent any unwanted interference it is best to keep a separate container with fresh Python installation for each project that you do. The earlier you start doing this the less mess there will be in the end.

This container is called Virtual Environment and it is like an additional clean installation of Python based on your initial version. Thanks to that approach you can have as many different environments as you wish each with a completely different set of additional items installed on top of them.

There are two methods to create virtual environments. As a programmer you need to know command line so that is our method number 1. I know – why cannot they make it easier :)?. Well the wise men in our community had similar thoughts and they created virtual environment wrappers. Using them creation of a new environment is super easy so this will be our way to make a new project space. Method number 2 is just use PyCharm’s great Project interface.

Creating Virtual Environment

The main library installing tool for Python 3 is pip. Invoking it is the same on Windows / Linux and MacOS. Follow the next few steps to get your first Virtual Environment ready.

Install Libraries and Create Your Environment

Please note that the prompt in the Windows Terminal now has changed to: (test_env_1) C:\Users\Kilthar> – you have your new Virtual Environment’s name in parenthesis on the left of it. This means that this environment is active currently. There can be only one environment active in any Terminal instance. When switching environments the one used so far gets deactivated first and a new one activated (we’ll get to it soon).

All your environments get stored by default in folder: C:\Users\Your_User_Name\Envs\

Make a Project’s Folder & Bind It to the Environment

Learn to Activate, Deactivate & Remove Environments

Now let’s see how to deactivate and activate an already existing environment. Since our test_env_1 environment is currently active let’s deactivate it.

If you look at the terminal’s output above you will notice that the prompt has changed to:  C:\Users\Kilthar\Documents\GitHub\test_dev_1> – the environment’s name is no longer in parenthesis before the prompt. This means Virtual Environment is deactivated within this terminal’s instance.

When you close the terminal the environment in it get’s deactivated automatically. Now let’s activate our environment again.

Pay attention to what happened when we used the last command: we were able to activate our test_env_1 from C:\ folder. You can call your environment from any folder and the current working directory will automatically change to what you used to bind as your project’s directory!

When we are done with the use of any given environment we can easily delete it.

Conclusions

And that’s it for now. We have covered Python 3 installation for Windows. Making and managing virtual environments and selecting Integrated Development Environment.

Your system should be ready for programming in Python 3. See you in the next post where we launch PyCharm and create our first project and learn most important settings of the IDE.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Created by: Tomasz Kluczkowski

Copyright © Tomasz Kluczkowski

Created by: Tomasz Kluczkowski

Copyright © 2017