Basic Windows Setup
This is a very basic guide to getting your Windows environment prepped and ready to run Python.
Please note that there are limitless possibilities and choices when it comes to most of these steps. The steps below only show one specific way to set things up. You are free to explore as you wish!
The steps below will have you install Notepad++ as your text editor and Miniconda as your Python interpreter.
Install Python
The interpreter that this guide is recommending comes from a utility called
Miniconda
. It's located here: https://conda.io/miniconda.html
There are many benefits to using this interpreter in Windows. The largest
benefit is that you do not need to install a C/C++ compiler in order to
install some Python packages (e.g. pycrypto
).
We recommend installing the latest release of Python 3. You should only choose
Python 2 if you have a need for it. Another great thing about Miniconda
is
that you can start with Python 3, but you can install Python 2 at a later date.
This will use conda environments (not covered here; see
the official docs).
Installing Miniconda
- Download the
Python 3.6
installer from https://conda.io/miniconda.html (probably 64-bit) - Run the installer
- Select the defaults, but stop at
Advanced Installation Options
. - Wait for Miniconda to finish installing
You may need to log out and back in again. YMMV.
Text editors
The best way to write Python code is with an enhanced text editor. There are a ton of options in this realm, along with opinions. Here are a few Windows applications listed in order of easiest (least features) to hardest (lots of features)
- Easy
- Notepad++: Freeware, Windows only
- Some setup effort
- Visual Studio Code: Open source, cross platform
- SublimeText: Cross platform, not free
- Atom.io: Open source, cross platform
- Most amount of effort
- PyCharm: Has both free and paid versions
- Visual Studio: Has both free and paid versions
If you like the command-line, there's always Vim!
For the sake of this guide, we'll use Notepad++. If you grow out of the limited feature set of Notepad++, we strongly recommend moving to something else.
Installing Notepad++
- Download the installer from https://notepad-plus-plus.org/
- Run the installer
- Select all of the defaults
Notepad++ Settings
We recommend changing your tabs so that Notepad++ will insert 4 spaces each
time you press the Tab
key on your keyboard. This will make you compliant
with PEP8.
- Settings -> Preferences
- Select
Language
and checkReplace by space
in theTab settings
section and make sure the size is set to4
Using your environment
We can finally start to write some Python code!
Create a Python script
The first step is to create a Python file. Here's one way to do it:
- Open Notepad++
- Select
File -> New
; you should have a new tab - Save the empty file with
File -> Save as...
Saving an empty file with a .py
extension will allow the editor to enable
syntax highlighting. That makes things much easier to code!
Create the Python code you want to run. Maybe this:
def say_hello():
print('Hello, World!')
if __name__ == '__main__':
say_hello()
Save the file when you are done editing.
It should look something like this:
Run the script
- From the start menu, select
Command Prompt
- Change to the directory you saved your script above. Maybe:
cd %USERPROFILE%\Desktop
if you saved it to you Desktop - Run the script with
python <scriptname>
. For example, if you saved your script ashello.py
, you would run:python hello.py
Here's what my command window looks like:
Conclusion
These directions show just one of the many ways to set up a Python environment on Windows. There are many more options of interpreters, text editors, and full blown Integrated Development Environments (IDEs). We also haven't covered any of the 138,120 projects on pypi.org (as of 7-MAY-2018)!